Add chunkFilename: "[id].[contenthash].js" option to webpack config to allow for cache busting when the chunks change, note that this doesn’t affect the filenames of the entry points like app.js since the hash there is added by mix phx.digest
(Optional) Compress /\.(js|css|svg)$/ via webpack using brotli, because why not (and in part thanks to #3840). This would mostly affect the chunks.
Update Plug.Static options in endpoint.ex to include gzip: true, brotli: true
I have no experience/knowledge here but it sounds like a great idea! I wonder if there’s even a chance LiveView would welcome the changes upstream as a PR/if it would be easier to accomplish cleanly within LiveView itself if you fork it? Maybe open an issue on LiveView to see if they have thoughts/are open to it in a PR, or as a hook/config option to make it easier to do within a Phoenix app if it adds some complexity? And I’m curious what you find, it seems like a good idea, but I’ve never tried it in general so not sure how much complexity/what the tradeoffs are…
What’s the easiest way for the br file generated by Webpack to end up with the same hash as the others?
I use chunkFilename: "[id].[contenthash].js" in webpack. I don’t think I need the hash to be the same as from mix phx.digest since I don’t reference these files in phoenix. Webpack does all the lazy loading.
I’ve recently come across asset_import. You might find it interesting.
Thanks, will check it out. But I think I like the dynamic import approach better.
My entry file as well as the app’s css file would benefit from the brotli compression. I ended up writing a mix task that will add the hash to the .br files generated by Webpack.
In prod or in dev? In dev it should work as is, as Phoenix is not referencing them by their hash name. But in prod, Phoenix will switch to the digested file from cache_manifest.json. In which case, the brotli equivalents will need to have the same filename in order to be used.
Also, my app is behind Nginx and you can configure Nginx to brotli compress on the fly or/and use static already compressed files. If you also use Nginx in front of your app, maybe you’re seeing the files compressed on the fly.