GoogleChromeLabs / sw-precache

[Deprecated] A node module to generate service worker code that will precache specific resources so they work offline.
https://developers.google.com/web/tools/workbox/guides/migrations/migrate-from-sw
Apache License 2.0
5.22k stars 388 forks source link

Not caching a single script. #323

Closed smatthews1999 closed 7 years ago

smatthews1999 commented 7 years ago

Hi guys. Kudos on a super tool. I am using this with much success but am having issues with a single script not being served by the service worker, even though it matches the wildcard in the config file.

The file in question is the file beginning with "vendor". config ...

module.exports = {
  navigateFallback: '/index.html',
  stripPrefix: 'dist',
  root: 'dist/',
  staticFileGlobs: [
    'dist/index.html',
    'dist/**.js',
    'dist/**.css',
    'dist/**.png',
    'dist/**.eot',
    'dist/**.woff2',
    'dist/**.ttf',
    'dist/**.waff',
    'dist/**.css',
    'dist/**.svg',
    'dist/assets/**.svg',
    'dist/assets/**.png'
  ]
};

image

I apologize if this is an error on my part. I did search for a while trying to find a solution.

jeffposnick commented 7 years ago

How are you running sw-precache, i.e. what's your build process? Are you sure that you're generating your service worker after all the steps that bundle your JavaScript have completed?

Based on what you're seeing, it makes me think that the service worker generation is happening in parallel with your bundling, and that your vendor.[hash].bundle.js isn't written to disk at the time that sw-precache is doing its thing.

If you're using Webpack for bundling, I'd recommend using sw-precache-webpack-plugin, which should know how to properly time itself so that it waits until your build is otherwise finished before it generates its service worker.

smatthews1999 commented 7 years ago

Thanks I found the problem. The compiled script is 2.11 mb and the max size is 2.1. Any way I can tweak that limit?

jeffposnick commented 7 years ago

Yes, via https://github.com/GoogleChrome/sw-precache#maximumfilesizetocacheinbytes-number

(As a general best practice, shipping a that much JS code in a single bundle is probably going to lead to performance issues for your users.)