-
Notifications
You must be signed in to change notification settings - Fork 10.3k
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
FEATURE: Encourage caching by giving each build of bundle.js a unique name #27
Comments
Is there a timeline on this? Or some hints on what would have to be done to make this work? Thanks! |
No one is working or has signaled plans to work on this yet afaik. You're
|
@KyleAMathews thanks ;) I assume we would want this to be a configurable option? Or always on? |
My gut reaction is default on but configurable.
|
One tricky thing about using Webpack's default hash is we can't determine the name until after it's built meaning we wouldn't easily be able pass the bundle.js file path to the HTML template. Which means we should just generate our own unique bundle name(s). Perhaps the easiest way to do this is to use the timestamp when |
Is it crazy to suggest using some sort of template string as the path to the bundle file then doing a pass after the build to replace the template string with the generated filename? |
@wyattanderson not crazy :) just mildly tricky. Would be a great PR if you want to work on it. Just added styles.css output on prod builds so we're ready for this. |
This was my solution, from my top-level
Then in
So every build you get one new cache buster value based on the current time. |
webpack/webpack#86 has some related discussion. It looks like if we change
The regex could be a user option if it needs to be more complex. |
A done plugin stage which opens up every page, regexes a file for a bundle tag, replaces the tag with the contenthash, and rewrites the file back to the disk (with or without a tmp file) is going to have a lot of I/O. We should try and look for a solution which writes the html files correctly the first time. Here's my idea for getting this in. It will be a breaking change (as bundle.js will no longer exist and most people right now are doing Create the javascript and css prior to building the pages (#253 has a pretty good start on this). We would just change the order. Pass the compiled assets information as an argument to the static site generation stage (maybe using DefinePlugin as Change the userland request of the bundle.js to something like the following. These helper components will just rip the asset information out of the defineplugin during build and just a standard bundle tag in development. import { GatsbyJs, GatsbyCss } from 'gatsby-helpers'
// defaults to bundle.js
<GatsbyJs />
// get a different entry point
<GatsbyJs entry='custom' /> Maybe rename the default bundle.js and styles.css to |
I agree avoiding rewriting every page would be much much better. And no need to fear breakage — that's why https://github.com/gatsbyjs/gatsby#warning is there 😝 Also to support code splitting, we'd need the ability to track and pass to different pages which additional JS chunks they should load. |
I didn't really think about the multiple chunks. For entry points with multiple chunks we would probably have to aim for a more react-helmet like API and return arrays of components, rather than a single component. import { assets } from 'gatsby-helpers'
// defaults
{assets.js}
{assets.css}
// if the user wants to grab a specific chunk
{assets.byChunk('chunkname')}
{assets.byChunk('chunkname', 'js')}
{assets.byChunk('chunkname', 'css')}
// if the user wants to get it all
{assets.raw} In order to figure out which chunks to load based on the current path, we can use the fact that node-modules are singletons and register the current path into the |
Yeah, that sounds like a good plan. |
Until we can get hashed bundle names in, I added a cache buster per @scottnonnenberg's suggestion gatsbyjs/gatsby-starter-default@c1eee90 |
(to the starters) |
This issue has been automatically closed due to inactivity. |
Currently someone can visit a new page and if they've cached the old bundle.js in their browser, after loading that, the new page will go blank as the old bundle.js doesn't know yet about it.
The text was updated successfully, but these errors were encountered: