-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
[4.0] Proper cache invalidation of the static assets [.js/.css] #32485
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
[4.0] Proper cache invalidation of the static assets [.js/.css] #32485
Conversation
|
@dgrammatiko Create the appropriate Joomla.assets.json files for all the menus Create the appropriate Joomla.assets.json files for all the templates Create the appropriate Joomla.assets.json files for all the componentes Create the appropriate Joomla.assets.json files for all the categories Create the appropriate Joomla.assets.json files for all the category Create the appropriate Joomla.assets.json files for all the article Create the appropriate Joomla.assets.json files for all the articles Create the appropriate Joomla.assets.json files for all the languages Create the appropriate Joomla.assets.json files for all the hashtags Create the appropriate Joomla.assets.json files for all the contents Create the appropriate Joomla.assets.json files for all the users Create the appropriate Joomla.assets.json files for all the fields Create the appropriate Joomla.assets.json files for all the contacts Create the appropriate Joomla.assets.json files for all the banners Create the appropriate Joomla.assets.json files for all the weblinks Create the appropriate Joomla.assets.json files for all the extensions ... Etc. |
|
hm, by default |
Yeah, it uses the PHP mediaVersion method but this method is tightly coupled to the Joomla version so all the assets will be invalidated in each Joomla update. With this approach the hash is generated from the actual content of the file, thus it will only change if the content of the file changed, win. @Fedik this doesn't need some special code on the PHP side, it works fine already |
|
@Stuartemk this PR covers ALL the core Joomla components and the system assets. It doesn't cover Modules and Plugins as there are not asset.json there yet. Also, the templates will be covered once we transition them to the Child mode, I'm working on it |
it does not required, if the plugin or module have only 1 css/js, it does not make much sense, I guess |
Well, I disagree, the point is that if you have a |
|
Can you convince me please on the benefits of this PR over the current method. Is it really such a bad thing to revalidate assets on each release. |
Think a bit about the global audience of Joomla here.
There is even a case for the privileged 1st world users: roaming |
I suspect that thinking the browser cache will maintain assets for such long periods of time is unlikely - but I have nothing more than a feeling to back that up - for the exact reason you state about consuming storage Plus thats only an argument for applying this to frontend assets and not all assets.
Wouldnt using the cdn version of an asset be even more efficient. So you only ever cache one version of a jquery? Having said all of that - this PR works and does as it says |
|
I have tested this item ✅ successfully on 04ab752 This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/32485. |
Actually, the browser is quite dumb in this case and will try to hold on the file as long as the server tells it. So, if you have
That's not the case since spectre and meltdown. Browsers now have double keyed caches per domain. If you have a script src to a cdn for jquery in your site and also joomla.org has the same script tag these two sites will never share the same cached file due to potential leaks cross-domain (security is hard). If you want to read more this is a good resource: whatwg/fetch#904 (comment) |
Oh I didnt know that - thanks for the link and info |
|
I have tested this item ✅ successfully on 04ab752 This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/32485. |
|
RTC This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/32485. |
|
Can we not run this in the build.php file like we do the gzip command? seems like a relatively safe thing to do. I mean it's slight overkill as in theory it wouldn't be required but shouldn't cause any issues. |
Sure. So basically there gonna be 3 node scripts that will run before the build.php (in this order):
|
@dgrammatiko do you want to add this here or do another PR, if you will do another I am going to merge this one |
No, there are a couple more PRs pending for the internal tracking of the static assets but those will be separate PRs |
Pull Request for Issue # .
The problem
For some years now Joomla has a
mediaversionPHP function which essentially creates a hash from the Joomla version. This was/is essential the weird part at the end of all the js/css files (?8567748356) and the reason for its existence was/is to invalidate the browser cache (the filename is the same but somehow we need to tell the browser to re fetch the content because there's a new Joomla version so the file might have been changed). But the process is extremely inefficient because FOR EVERY JOOMLA UPDATE WE INVALIDATE ALL THE STATIC ASSETS whether there was a change or not!The solution
Since the introduction of Web Assets from @Fedik we have a registry where we can declaratively set some attributes. Amongst those attributes is also the
versionand this has been already mentioned by me a year ago when I was building the first truly SPA/PWA template: dgrammatiko/sloth@f315111 Nobody picked the code to do a PR so here I am doing it myselfSummary of Changes
Testing Instructions
npm installornpm cimedia/system/joomla.asset.jsontomedia/system/default-joomla.asset.jsonnpm run versioningversionattribute is added in every style/script assetActual result BEFORE applying this Pull Request
{ "name": "core", "type": "script", "class": "CoreAssetItem", "uri": "system/core.min.js" },Expected result AFTER applying this Pull Request
{ "name": "core", "type": "script", "class": "CoreAssetItem", "uri": "system/core.min.js", "version": "8f1a05a7e6e6fad83d22a4a5b67bafbb04ddc875" },Documentation Changes Required
This basically as the gzip command affects only the release leader or anyone that will create a Joomla release but I guess this needs to be added in the steps for creating a release
@wilsonge
TODO
Joomla.assets.jsonfiles for all the modulesJoomla.assets.jsonfiles for all the plugins