pwa-studio icon indicating copy to clipboard operation
pwa-studio copied to clipboard

[feature]: Improve caching for js bundles/chunks

Open Jordaneisenburger opened this issue 4 years ago • 11 comments

Is your feature request related to a problem? Please describe. For a PWA Studio developer using the scaffolder to kickstart their project we'd expect them to build custom code ontop of the scaffolded app meaning that the functionalities that change a lot will be their own local code instead of node_modules.

What happens right now is that we on buildtime we create a client.js bundle that holds local code but also @magento packages. Tese packages would add an extra x kb to the client.js bundle that needs to download everytime when some local code changes even when the @magento packages did not change.

Ideally we split @magento packages into it's own bundle so that the browser can have it in cache for longer periods of time and it doesnt have to redownload between local changes and will for example only change whenever the store is being upgraded to a newer version of PWA Studio meaning we have longer cache validity.

Describe the solution you'd like Split @magento packages into their own bundle via webpack cacheGroups.

Additional context Before change to webpack: before

After change to webpack: after

Benefits:

  • The user doesnt have to re-download all the magento code that didnt change when revisiting.
  • All the lazy loaded components are still in their own chunk but the core components we need are now packed into their own bundle
  • Reduce client.js by 40ish kb

Definetly not a subject expert so would love to hear anyones feedback/opinions!

Please let us know what packages this feature is in regards to:

  • [ ] venia-concept
  • [ ] venia-ui
  • [X] pwa-buildpack
  • [ ] peregrine
  • [ ] pwa-devdocs
  • [ ] upward-js
  • [ ] upward-spec
  • [ ] create-pwa

Jordaneisenburger avatar Oct 15 '21 15:10 Jordaneisenburger

Hi @Jordaneisenburger. Thank you for your report. To help us process this issue please make sure that you provided sufficient information.

Please, add a comment to assign the issue: @magento I am working on this


m2-assistant[bot] avatar Oct 15 '21 15:10 m2-assistant[bot]

@magento I am working on this

Jordaneisenburger avatar Oct 15 '21 15:10 Jordaneisenburger

@magento export issue to JIRA project PWA as Story

supernova-at avatar Nov 16 '21 21:11 supernova-at

:white_check_mark: Jira issue https://jira.corp.magento.com/browse/PWA-2414 is successfully created for this GitHub issue.

github-jira-sync-bot avatar Nov 16 '21 21:11 github-jira-sync-bot

hello @Jordaneisenburger could you send your diff for this feature I want to move the code of my custom vendor into a standalone bundle/chunk

0m3r avatar Jun 09 '22 13:06 0m3r

hello @Jordaneisenburger could you send your diff for this feature I want to move the code of my custom vendor into a standalone bundle/chunk

Something like below @vvendor/kernel/lib/intercept.js

       const builtins = targets.of('@magento/pwa-buildpack');
       builtins.webpackCompiler.tap(compiler => {
           const cacheGroups = compiler?.options?.optimization?.splitChunks?.cacheGroups;
           if (cacheGroups && typeof cacheGroups.vvendor === 'undefined') {
               cacheGroups.vvendor = {
                  test: /[\/]node_modules[\/](@vvendor)[\/]/,
                  reuseExistingChunk: true,
                  name: 'vvendor',
              };
           }
       }); 

0m3r avatar Jun 10 '22 11:06 0m3r

@0m3r Are your way help to reduce the vendor bundle size?

huykon avatar Nov 23 '22 10:11 huykon

@huykon yes it worked for me in June, but I didn't test it in the latest version(s)

0m3r avatar Nov 26 '22 20:11 0m3r

@0m3r I tried your way but it doesn't reduce much size, do you have any others way?

huykon avatar Dec 01 '22 09:12 huykon