magento / pwa-studio

🛠Development tools to build, optimize and deploy Progressive Web Applications for Magento 2.
https://developer.adobe.com/commerce/pwa-studio/
Open Software License 3.0
1.06k stars 683 forks source link

[feature]: Improve caching for js bundles/chunks #3490

Closed Jordaneisenburger closed 1 month ago

Jordaneisenburger commented 2 years ago

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:

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:

m2-assistant[bot] commented 2 years ago

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


Jordaneisenburger commented 2 years ago

@magento I am working on this

supernova-at commented 2 years ago

@magento export issue to JIRA project PWA as Story

github-jira-sync-bot commented 2 years ago

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

0m3r commented 2 years ago

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 commented 2 years ago

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',
              };
           }
       }); 
huykon commented 1 year ago

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

0m3r commented 1 year ago

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

huykon commented 1 year ago

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

glo82145 commented 4 months ago

@adobe export issue to Jira project PWA

github-jira-sync-bot commented 4 months ago

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