sw-precache-webpack-plugin: wepback public path make index.html cache not working.
- I’m submitting a bug report
- I’m submitting a feature request
- I’m submitting a support request
webpack version: 2.2.1
sw-precache-webpack-plugin version: 0.9.2
Please tell us about your environment: OSX 10.12.4
Browser: [Chrome 58.0.3029.110 (64-bit)]
Current behavior:
// webpack.config.js
...
output: {
publichPath: 'https://cdn.com/'
},
...
plugins: [
new SWPrecacheWebpackPlugin({
filename: 'sw.js',
staticFileGlobsIgnorePatterns: [/\.map$/]
})
]
//sw.js
...
var precacheConfig = [
['https://cdn.com/index.html', '1927d0eabd7c5d5d786731cf24b2675b']
...
That https://cdn.com/index.html make the index.html cache won’t work. Cause the request url won’t match.
Expected/desired behavior:
index.html can be cached properly.
If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem along with your:
- Webpack configuration:
// webpack.config.js
...
output: {
publichPath: 'https://cdn.com/'
},
...
plugins: [
new SWPrecacheWebpackPlugin({
filename: 'sw.js',
staticFileGlobsIgnorePatterns: [/\.map$/]
})
]
- Generated service worker (not minified):
//sw.js
...
var precacheConfig = [
['https://cdn.com/index.html', '1927d0eabd7c5d5d786731cf24b2675b']
...
About this issue
- Original URL
- State: open
- Created 7 years ago
- Comments: 27 (6 by maintainers)
Commits related to this issue
- remove public path for index.html #79 — committed to darrylsepeda/sw-precache-webpack-plugin by deleted user 7 years ago
- remove webpack public path for index.html #79 — committed to darrylsepeda/sw-precache-webpack-plugin by deleted user 7 years ago
- Merge pull request #1 from darrylsepeda/remove_public_path_index remove webpack public path for index.html #79 — committed to darrylsepeda/sw-precache-webpack-plugin by darrylsepeda 7 years ago
👍 For exposing an API for handling this use case. I have the exact same need as well. Some assets come from a CDN while some (index.html) need to come from the applications url.
it will output
index.htmlaloneSeems like a legitimate feature request, will think about an api for this unless you have a suggestion @darrylsepeda
I got the same issue with @lili21. All of my files is cached, but my webpack public path is directed to the other URL as explained by @lili21. So I can’t refresh my page while offline because my index file is pointed to cdn.
I’ve read @jeffposnick reference, but still can’t find any solution. What he actually did is comparing the public path and the origin then if it is different, dissable the Service Worker.
It is useless. My goal is to make this SW works no matter if the public path and the origin is different. Is there any way to overwrite the SW generated by sw-precache-webpack-plugin? so my index file can be cache correctly (not using webpack public path).
I’ve tried to overwrite my service worker generated by sw-precache-webpack-plugin manually from
http://cdn.com/index.htmltoindex.htmland the offline mode works well, but I can’t make it that way since it won’t be efficient if we should maintain our service worker file manually everytime someone re-build our app.Related: https://github.com/facebookincubator/create-react-app/pull/2432
(I’m not sure this is a supported use case.)