Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

static css chunks served with maxage=0 #5464

Closed
Enalmada opened this issue Oct 16, 2018 · 7 comments · Fixed by vercel/next-plugins#335
Closed

static css chunks served with maxage=0 #5464

Enalmada opened this issue Oct 16, 2018 · 7 comments · Fixed by vercel/next-plugins#335
Assignees
Labels
Upstream Related to using Next.js with a third-party dependency. (e.g., React, UI/icon libraries, etc.).

Comments

@Enalmada
Copy link
Contributor

Enalmada commented Oct 16, 2018

Bug report

Describe the bug

static css files appear to be served with sub-optimal cache-control:

/_next/static/css/commons.4e4de3e2.chunk.css
/_next/static/css/styles.4015be53.chunk.css
served with:
cache-control: public, max-age=0

I am new to Next.js behavior so apologies if this is not really a bug and css chunk shouldn't be served max-age=31536000, immutable for some reason. I just assume that the chunk hash (commons.4e4de3e2.chunk.css) ensure these things could/should be immutable but I am ready to be educated.

To Reproduce

Steps to reproduce the behavior, please provide code snippets or a repository:

  1. Go to any next.js page in chrome right click on any element and inspect element
  2. Right click on any element and inspect element
  3. Look at the network tab and click on a /_next/static/css
  4. See cache-control is "public, max-age=0"

Expected behavior

I expect them to be served with "cache-control: public, max-age=31536000, immutable" like everything else in the /_next/static seems to be served with.

System information

  • OS: [e.g. macOS, Windows]
  • Browser: chrome
  • Version of Next.js: 7.0.2

Additional context

You can see this here: https://client.gelltest.com/
I can provide this sample repo if this for some reason isn't immediately and obviously reproducible.
(Identified after looking into css due to this comment: https://spectrum.chat/?t=9f9f43b8-ec8b-45e5-a8e3-5b57a62e9e67)

@timneutkens
Copy link
Member

@timneutkens timneutkens added Type: Bug Upstream Related to using Next.js with a third-party dependency. (e.g., React, UI/icon libraries, etc.). labels Oct 17, 2018
@Enalmada
Copy link
Contributor Author

@timneutkens I tried to start a pull request changing css-loader-config.js lines to static/chunks (per spectrum suggestion above) but when testing, I see that the css files are being fetched twice, once from static/css and static/chunks directory.

image

I can't quite tell what is causing the duplicate. Perhaps something in Head when fetching chunks and css needs to change too to filter out one or the other?

@lennerd
Copy link

lennerd commented Oct 23, 2018

Sidenote: the max-age=0 is also set for all other assets in the static folder.

screenshot 2018-10-23 17 25 51

@lennerd
Copy link

lennerd commented Oct 23, 2018

Sorry, just realised this is intentional: #1791

@Enalmada
Copy link
Contributor Author

Should I move this to next-plugins?

@Enalmada
Copy link
Contributor Author

@quietshu I am trying to make a middleware for the next.js community (https://github.com/Enalmada/next-preload-headers) that is useless without this fix. @timneutkens implied that it might be an easy fix just changing static/css to static/chunks...I tried but got some strange behavior I noted above. I am hoping that with your superior experience you might be able to immediately tell what additional thing needs to be done to fix this for good.

@Enalmada
Copy link
Contributor Author

I believe I have solved this bug with the following pull requests. I don't completely understand what I am doing but because this bug is hurting me I am trying to do my best. Please review:
#5675
vercel/next-plugins#335

timneutkens pushed a commit to vercel/next-plugins that referenced this issue Nov 14, 2018
Part of the fix for vercel/next.js#5464
The other part is a next.js change I am checking in now.

Fixes vercel/next.js#5464 
Fixes #243
chrisvxd pushed a commit to hydrateio/next-css that referenced this issue Feb 27, 2019
Part of the fix for vercel/next.js#5464
The other part is a next.js change I am checking in now.

Fixes vercel/next.js#5464 
Fixes #243
@lock lock bot locked as resolved and limited conversation to collaborators Nov 14, 2019
snowMan128 added a commit to snowMan128/next-plugins that referenced this issue Mar 25, 2024
Part of the fix for vercel/next.js#5464
The other part is a next.js change I am checking in now.

Fixes vercel/next.js#5464 
Fixes #243
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Upstream Related to using Next.js with a third-party dependency. (e.g., React, UI/icon libraries, etc.).
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants