Skip to content

Commit b06d388

Browse files
authored
Inline styles for better performance (#22)
* Inline styles for better performance * Optimize images
1 parent 463eec5 commit b06d388

File tree

6 files changed

+1014
-817
lines changed

6 files changed

+1014
-817
lines changed

app/globals.css

-3
This file was deleted.

app/layout.tsx

+15-13
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
1-
import { CartCountProvider } from '#/components/cart-count-context';
2-
import { Header } from '#/components/header';
3-
import { Sidebar } from '#/components/sidebar';
4-
import { GeistSans } from 'geist/font/sans';
5-
import { Metadata } from 'next';
6-
import './globals.css';
1+
import { CartCountProvider } from "#/components/cart-count-context";
2+
import { Header } from "#/components/header";
3+
import { Sidebar } from "#/components/sidebar";
4+
import { Metadata } from "next";
5+
import { GlobalStyles } from "./styles";
76

87
export const metadata: Metadata = {
9-
metadataBase: new URL('https://partialprerendering.com'),
10-
title: 'Next.js Partial Prerendering',
11-
description: 'A demo of Next.js using Partial Prerendering.',
8+
metadataBase: new URL("https://partialprerendering.com"),
9+
title: "Next.js Partial Prerendering",
10+
description: "A demo of Next.js using Partial Prerendering.",
1211
openGraph: {
13-
title: 'Next.js Partial Prerendering',
14-
description: 'A demo of Next.js using Partial Prerendering.',
12+
title: "Next.js Partial Prerendering",
13+
description: "A demo of Next.js using Partial Prerendering.",
1514
},
1615
twitter: {
17-
card: 'summary_large_image',
16+
card: "summary_large_image",
1817
},
1918
};
2019

@@ -24,7 +23,10 @@ export default function RootLayout({
2423
children: React.ReactNode;
2524
}) {
2625
return (
27-
<html lang="en" className={`[color-scheme:dark] ${GeistSans.variable}`}>
26+
<html lang="en" className={`[color-scheme:dark]`}>
27+
<head>
28+
<GlobalStyles />
29+
</head>
2830
<body className="overflow-y-scroll bg-gray-1100 bg-[url('/grid.svg')] pb-36">
2931
<Sidebar />
3032
<div className="lg:pl-72">

app/styles.tsx

+13
Large diffs are not rendered by default.

components/single-product.tsx

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import { Pricing } from '#/components/pricing';
2-
import type { Product } from '#/types/product';
3-
import { ProductRating } from '#/components/product-rating';
4-
import Image from 'next/image';
1+
import { Pricing } from "#/components/pricing";
2+
import type { Product } from "#/types/product";
3+
import { ProductRating } from "#/components/product-rating";
4+
import Image from "next/image";
55

66
export async function SingleProduct() {
77
const product: Product = await fetch(
8-
`https://app-router-api.vercel.app/api/products?id=1`,
8+
`https://app-router-api.vercel.app/api/products?id=1`
99
).then((res) => res.json());
1010

1111
return (
@@ -31,7 +31,7 @@ export async function SingleProduct() {
3131
alt={product.name}
3232
fill
3333
sizes="(min-width: 1184px) 75px, (min-width: 768px) 8.33vw, 16.66vw"
34-
priority
34+
loading="lazy"
3535
/>
3636
</div>
3737
<div className="relative aspect-square w-1/3">
@@ -41,7 +41,7 @@ export async function SingleProduct() {
4141
alt={product.name}
4242
fill
4343
sizes="(min-width: 1184px) 75px, (min-width: 768px) 8.33vw, 16.66vw"
44-
priority
44+
loading="lazy"
4545
/>
4646
</div>
4747
<div className="relative aspect-square w-1/3">
@@ -51,7 +51,7 @@ export async function SingleProduct() {
5151
alt={product.name}
5252
fill
5353
sizes="(min-width: 1184px) 75px, (min-width: 768px) 8.33vw, 16.66vw"
54-
priority
54+
loading="lazy"
5555
/>
5656
</div>
5757
</div>

lib/constants.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
// Times are in milliseconds
2-
export const delayShippingEstimate = 400;
3-
export const delayRecommendedProducts = 800;
4-
export const delayReviews = 1000;
2+
export const delayShippingEstimate = 200;
3+
export const delayRecommendedProducts = 500;
4+
export const delayReviews = 600;

0 commit comments

Comments
 (0)