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

Only caches visited routes #24

matthewpull opened this Issue Jan 4, 2018 · 7 comments


None yet
4 participants

matthewpull commented Jan 4, 2018

I've been playing around with the workbox component of the pwa module for a couple of days and have got it working with my hosting environment, but I seem to have a configuration problem.

For some reason only routes that I visit are being cached and then available offline. As far as I am concerned, this is not offline support as trying to navigate to other routes produces a browser error page.

This is strange, as in the sw.js file I can see that all of the nuxt js files for each route are being precached. However, trying to navigate to a route that I didn't visit while online gives the standard browser error (even though the corresponding nuxt js file is cached).

Is this the expected behaviour or is my configuration incorrect?

This question is available on Nuxt.js community (#c17)

This comment has been minimized.

matthewpull commented Jan 4, 2018

It is worth noting that I have my application set up as a single page app (SPA)


This comment has been minimized.

ahus1 commented Mar 28, 2018

I experience the same situation with a generated nuxt site. I wonder if the pwa-module could pre-cache the 200.html and fallback to this file in offline mode.

AFAIK 200.html will either display the route if it exists, or show the custom error page if doesn't.


This comment has been minimized.


pi0 commented Apr 2, 2018

#59 should fix it.

@pi0 pi0 closed this in 76de33c Apr 2, 2018


This comment has been minimized.

ahus1 commented Apr 2, 2018

@pi0 - I looked at the PR and I don't think it fixes the issue described here:

With the PR #59 you can now disable runtime caching completely, so NO route is cached (only nuxt resources are cached).

I think what this issues needs is to have ALL available routes be part of the precache.

Therefore I vote for re-opening this issue.

@pi0 pi0 reopened this Apr 2, 2018

manniL added a commit to manniL/pwa-module that referenced this issue Apr 4, 2018

feat(worbox): add offline option for making it optional (nuxt-communi…

Make all-inclusive NetworkFirst route registration optional.

Fixes nuxt-community#24.

This comment has been minimized.

ahus1 commented Sep 21, 2018

I tested this again and to me it seems that the behaviour changed in the latest releases and it seems that the issue is now resolved and can be closed.

Tested with: Nuxt 2.0.0 and @nuxtjs/pwa 2.6.0

The default behavior is now as follows:

  • all JS/CSS-contents of the _nuxt folder are precached as default

To make my app work fully in offline mode, I added the following:

  • pre-cache all images to ensure they are available offline as well
  • specify the fallback as the offline page for non-visited pages

My configuration now looks like this:

module.exports = {
  /* ... */
  workbox: {
    globPatterns: ['**/*.{js,css}', '**/img/*'],
    offlinePage: '/404.html'
  generate: {
    fallback: true

If you don't set fallback: true, you would use 200.html as the offline page I think (but I didn't test this). The version I tested pre-caches the offline page automatically as well.

When I test this, a page previously not visited will return the contents, as the Nuxt fallback page will display the correct contents. If the page does not exist, Nuxt will evaluate the routes and show the 404 page design.


This comment has been minimized.


galvez commented Sep 21, 2018

@ahus1 You could also use the offlineAssets option but glad to see this example with globPattern working -- I hadn't used it like that before. I'll try and enhance this further soon.

@galvez galvez closed this Sep 21, 2018


This comment has been minimized.


pi0 commented Sep 22, 2018

@ahus1 Happy to hear that it is finally working for you.😊 Enjoy coding and feel free opening new issues if you have observed any special problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment