next.js icon indicating copy to clipboard operation
next.js copied to clipboard

feat(etag-test): restore ETag behavior for static pre-rendered page

Open maheshbhatiya73 opened this issue 7 months ago • 1 comments

For Contributors

Adding or Updating Examples

  • Follows the examples contribution guide: https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md
  • Linting and build verified via pnpm build && pnpm lint
  • Demonstrates ETag behavior in both Next.js 14 and 15
  • Helpful for debugging static pre-rendered page caching

What?

This PR adds an example under examples/etag-test that demonstrates how to restore ETag support for static pre-rendered pages in Next.js 15, and how the behavior compares to Next.js 14.

Why?

Starting with Next.js 15, React Server Components (RSC) are streamed by default, which disables automatic ETag headers on static responses.
Many developers upgrading from v14 expect 304 caching to work, but observe 200s instead.
This example helps validate and test that behavior explicitly.

How?

  • Added a minimal etag-test example with a static route (pages/index.tsx)
  • Verified that ETag headers are properly included
  • Tested curl with If-None-Match to confirm 304 Not Modified response
  • Example works with both Next.js 14 and 15 — great for comparing caching behavior

Fixes: #80452


Example path: examples/etag-test
Works in:

  • Next.js 14.1.4 → Static pages send ETag by default
  • Next.js 15.3.3 → Restores ETag by avoiding default RSC streaming behavior

To test:

pnpm install
pnpm build
pnpm start
curl -I http://localhost:3000/
curl -I -H 'If-None-Match: "<etag-value>"' http://localhost:3000/

maheshbhatiya73 avatar Jun 13 '25 15:06 maheshbhatiya73

Allow CI Workflow Run

  • [ ] approve CI run for commit: 36cf7e11d784500844c07d7aa485add710c0b709

Note: this should only be enabled once the PR is ready to go and can only be enabled by a maintainer

ijjk avatar Jun 13 '25 15:06 ijjk