NekR / offline-plugin

Offline plugin (ServiceWorker, AppCache) for webpack (https://webpack.js.org/)
MIT License
4.51k stars 294 forks source link

appcache fallback (SPA) doesn't work #369

Open wclr opened 6 years ago

wclr commented 6 years ago

I have appShell option configured:

appShell: '/',

generated manifest:

CACHE MANIFEST
#ver:2018-4-15 02:02:43
#plugin:4.9.0

CACHE:
/bundles/18f4426789edc9a053f7.worker.js
/bundles/1003-1139-1140.lp.ru-8304ca6896f912a71a94.js
/bundles/1003-1139-1140-1288.lp.ru-158bd16363e2848602fc.js
/bundles/1003-1139-1140.geonames.ru-0db197ba553df3748f0d.js
/bundles/1003-1139-1140.geonames.en-1bcf43d7dc55642a1236.js
/bundles/1003.lp.ru-57a31de2577ade74cc76.js
/bundles/cities15000-8eeebdc8de3eee217bc0.js
/bundles/app-9bb92bf87ad5aed4cb67.js
/bundles/fonts-e129712248aa27593003.js
/bundles/vendor-33d2c45daef7f3aece84.js
/bundles/../

NETWORK:
*

FALLBACK:
/bundles/ /

In appcache offline mode path site.com/ works, but any other paths like `site.com/something doesn't work. Service worker version works ok for such paths. Tested in Firefox and Chrome.

What can be the problem?

NekR commented 6 years ago

Well, issues is that FALLBACK is generated only to /bundles/ subdirectory. Probably appShell does it wrong. Can you show me the metadata generated in ServiceWorker file? (json data in the beginning of the file), and your offline-plugin config if possible.

wclr commented 6 years ago

You mean this?

var __wpo = {
  "assets": {
    "main": [
      "/bundles/18f4426789edc9a053f7.worker.js",
      "/bundles/1003-1139-1140.lp.ru-8304ca6896f912a71a94.js",
      "/bundles/1003-1139-1140-1288.lp.ru-158bd16363e2848602fc.js",
      "/bundles/1003-1139-1140.geonames.ru-0db197ba553df3748f0d.js",
      "/bundles/1003-1139-1140.geonames.en-1bcf43d7dc55642a1236.js",
      "/bundles/1003.lp.ru-57a31de2577ade74cc76.js",
      "/bundles/cities15000-8eeebdc8de3eee217bc0.js",
      "/bundles/app-9bb92bf87ad5aed4cb67.js",
      "/bundles/fonts-e129712248aa27593003.js",
      "/bundles/vendor-33d2c45daef7f3aece84.js",
      "/bundles/../"
    ],
    "additional": [],
    "optional": []
  },
  "externals": [],
  "hashesMap": {
    "82353bd325f24a09270a4fb02436ce699b7a2b99": "/bundles/18f4426789edc9a053f7.worker.js",
    "38a14853d53900fcd0169852e29b3f29999f3f5e": "/bundles/1003-1139-1140.lp.ru-8304ca6896f912a71a94.js",
    "6f739625f7c6e41978981a127ca4d9a59c635bd2": "/bundles/1003-1139-1140-1288.lp.ru-158bd16363e2848602fc.js",
    "d00675d98482ca19f2d5964c24c1528fb101aa03": "/bundles/1003-1139-1140.geonames.ru-0db197ba553df3748f0d.js",
    "0250760125eae8acdb31af649e8b279a1e23a1af": "/bundles/1003-1139-1140.geonames.en-1bcf43d7dc55642a1236.js",
    "98aca348c8bdf940e58b46fa94fea8d5c14ecee8": "/bundles/1003.lp.ru-57a31de2577ade74cc76.js",
    "4cb80abd37d68f41553ddecf02703728305631e6": "/bundles/cities15000-8eeebdc8de3eee217bc0.js",
    "b60e6c73f308366ef229d70366035e0a1ab7c8e5": "/bundles/app-9bb92bf87ad5aed4cb67.js",
    "720781880391efe1fe6ac2e84a16d3d589ff2614": "/bundles/fonts-e129712248aa27593003.js",
    "4da197c43b1bcdd4dbfe16cf13d7f93a2ea85f00": "/bundles/vendor-33d2c45daef7f3aece84.js",
    "ba16e2d7a29ef2e00c674077f123f88841d9c82d": "/bundles/../"
  },
  "strategy": "changed",
  "responseStrategy": "cache-first",
  "version": "2018-4-15 02:02:42",
  "name": "webpack-offline",
  "pluginVersion": "4.9.0",
  "relativePaths": false
};
NekR commented 6 years ago

@whitecolor Yeah, I meant that. But actually it doesn't have the information I was looking for, my bad. But the issues here is that you cache /bundles/ URL, but set appShell to / URL, which isn't cached. Just set it to `appShell: '/bundles/'.

But I guess you have /bundles/ specified as your publicPath, right? If so, then it's a bug because appShell option doesn't pick it up, as it should.

Let me know :-)

wclr commented 6 years ago

Yes this is the config for webpack output:

    path: join(outputPath!, 'bundles'),
    publicPath: '/bundles/'
NekR commented 6 years ago

@whitecolor thanks! Try to set appShell: '/bundles/'. I'm thinking about it now, if it's a bug or not. I'm not sure. appShell meant to receive an absolute path, so maybe not. At the very least, it should warn when supplied path is outside of ServiceWorker scope.

wclr commented 6 years ago

Try to set appShell: '/bundles/'

This seem not to help =(

http://my.app/?homescreen=1 can be opened offline.

NekR commented 6 years ago

Well, I'll need public url of the website to test the things. Can't help by just guessing stuff.

wclr commented 6 years ago

Public is still served only over https, will it be possible to test appcache?

NekR commented 6 years ago

Yeah, I can do that in old Safari. (btw no need to serve things from http, https only is great)

wclr commented 6 years ago

https://charta.life

wclr commented 6 years ago

Just noticed that my HTML template doesn't have manifest="appcache/manifest.appcache" in html, though it doesn't really change things. If you don't mind a couple of questions regarding this:

1) why manifest="appcache/manifest.appcache" in html is inserted (if it works without it)?

2) Is it possible not to insert it in webpack-html-plugin auto generated HTML?