Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updatestrategy's effect on assets in the 'main' section of caches #292

Closed
ismay opened this issue Aug 17, 2017 · 3 comments
Closed

Updatestrategy's effect on assets in the 'main' section of caches #292

ismay opened this issue Aug 17, 2017 · 3 comments

Comments

@ismay
Copy link

ismay commented Aug 17, 2017

I'm currently using the all updateStrategy because not all my assets have a hash appended to their filename. Only my clientside js does. And the docs state that in that case the all updateStrategy is best since it will re-verify all assets.

However, what confuses me is that the docs also state that for the changed updateStrategy:

With this strategy enabled, index.html file (or other files without dynamic name) should be placed in main section of the cache, otherwise they won't be revalidated.

Does that mean that all assets that are listed in main will be re-verified anyway, even when using the changed updateStrategy? Because that's a little unclear to me from the docs. Also, wouldn't basically everyone need to use the all updateStrategy, since a lot of builds will emit assets that aren't hashed?


Just for clarity, this is the current config I'm using, and the above question arose from me thinking about which updateStrategy would be best:

// https://github.com/ismay/ismaywolff.nl/blob/develop/webpack.config.client.prod.js#L154-L182
    new OfflinePlugin({
      autoUpdate: true,
      output: 'sw.js',
      version: process.env.RELEASE,
      updateStrategy: 'all',
      caches: {
        main: [
          ':externals:',
          'manifest.json',
          '*.js',
          '*.woff',
          '*.woff2',
          '*.png',
          '*.xml',
          '*.ico'
        ],
        additional: [],
        optional: []
      },
      externals: [
        '/index.html',
        'https://cdn.polyfill.io/v2/polyfill.min.js'
      ],
      AppCache: false,
      ServiceWorker: {
        events: true,
        navigateFallbackURL: '/'
      }
    })
@NekR
Copy link
Owner

NekR commented Aug 17, 2017

Actually, you're fighting a problem what doesn't exist. It's weird, but docs for updateStrategy are pretty much outdated. With changed strategy offline-plugin calculates files' hashes on its own, no matter what name they have. This also helps with files being renamed, i.e. if the hash is the same then file isn't redownloaded but rather just renamed.

Also, updateStrategy doesn't apply to externals. They're always revalidated/redownloaded on SW update.

@ismay
Copy link
Author

ismay commented Aug 18, 2017

Ah that's great! Thanks for clarifying!

@NekR
Copy link
Owner

NekR commented Aug 18, 2017

Great! :-)

@NekR NekR closed this as completed Aug 18, 2017
GGAlanSmithee added a commit that referenced this issue Sep 22, 2017
fixes #295 in response to #292

A bit unsure if this still applies @NekR or it should be removed

> With this strategy enabled, index.html (or other files without dynamic name) should be placed in main section of the cache, otherwise they won't be revalidated.
For ServiceWorker this means that only new files will be downloaded and missing files deleted from the cache.
For AppCache it's basically the same as previous strategies since AppCache revalidates all the assets. (HTTP status 304 rule still applies).
NekR pushed a commit that referenced this issue Oct 16, 2017
* Fixes thrown exceptions in apps using postMessage

My app uses postMessage for it's own purposes. This fixes an error that occurs when the appcache updates choke on messages from the application.

* Adds info regarding redirects not working

@NekR

In response to #303

* Update update-strategies.md

fixes #295 in response to #292

A bit unsure if this still applies @NekR or it should be removed

> With this strategy enabled, index.html (or other files without dynamic name) should be placed in main section of the cache, otherwise they won't be revalidated.
For ServiceWorker this means that only new files will be downloaded and missing files deleted from the cache.
For AppCache it's basically the same as previous strategies since AppCache revalidates all the assets. (HTTP status 304 rule still applies).

* Update FAQ.md

as asked for in #227

Also related to #228, but does not add any additional `events` doc

* 4.8.4

* update according to PR comments

* new -> new/changed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants