Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Workbox: cannot cache all files when build project

I use Vuejs and I use workbox-webpack-plugin in order to make my site offline, I want to cache a folder which contains all my files (3 files) like picture below, but when I build my project(using Laravel-mix). The main.js (which contains everything of Vue) cannot be cached in service-woker.js. I tried some ways to fix that but those didn't work. Does anybody face this issue, do you have any solution, many thanks!

->>picture-description

like image 564
Duc Trung Mai Avatar asked Jan 28 '26 06:01

Duc Trung Mai


1 Answers

EDIT: Some time ago, a guy on GitHub helped me figure this out.

It's because there's a Workbox config property called maximumFileSizeToCacheInBytes. By default it is set to 2MB, which means it will only cache files that are smaller than (or equal to) 2MB. Some of my built files are larger than that. I only needed to increase the maximumFileSizeToCacheInBytes to solve the issue and include those larger files in the generated service worker.

My updated Workbox config looks like this:

plugins: [
  new workboxPlugin({
    globDirectory: DIST_DIR,
    globPatterns: ['js/*.{html,js,css}'],
    maximumFileSizeToCacheInBytes: 5000000, // <-- Added (5 MB)
    swDest: path.join(DIST_DIR, 'sw.js'),
  }),
]
like image 197
Duc Trung Mai Avatar answered Jan 30 '26 23:01

Duc Trung Mai



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!