-
Notifications
You must be signed in to change notification settings - Fork 4.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
Scripts: Lazy loaded JavaScript files do not break browser cache upon changes #55397
Comments
Just to note: in development watch mode you probably don't want to use the contenthash. You can do that like this in a custom
|
@jsnajdr is working on lazy block loading for core blocks in #55585. The way he approached a similar issue was by using |
Yes, setting To avoid "polluting" the filenames, you can use a If you wanted all the plugin's files to use a common version number, like:
this should also be possible: the All this can be done without waiting for #55585, can be shipped on its own. |
Hi @gziolo , I am a beginner in open source contribution and I would like to work on this issue. |
Hi @rithik56, sounds great! Let us know when you have a PR ready for review 👍🏻 |
Thanks @gziolo , will let you know once the PR is ready |
Description
If you use wp-scripts in a custom project that uses lazy loading with react, the lazily-loading javascript files remain cached by the browser and load out-of-date versions.
To fix this, webpack recommend putting a contenthash into the filename so it's unique if anything changed. See:
https://webpack.js.org/guides/caching/
To add this to wp-scripts, we can simply modify that here:
gutenberg/packages/scripts/config/webpack.config.js
Line 117 in 58064cc
So that this:
Becomes this:
The main problem there is that if someone is enqueueing a file using it's name, it will now have a unique content hash. Therefore, this would be a breaking change.
I am not sure of another way to fix this though.
Please confirm that you have searched existing issues in the repo.
Yes
Please confirm that you have tested with all plugins deactivated except Gutenberg.
Yes
The text was updated successfully, but these errors were encountered: