-
Notifications
You must be signed in to change notification settings - Fork 104
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
wepback public path make index.html cache not working. #79
Comments
So index.html is not caching as you would like? Is it generated by webpack (using a loader like html-webpack-plugin)? |
no and yes. yes, it is generated by html-webpack-plugin. |
Related: facebook/create-react-app#2432 (I'm not sure this is a supported use case.) |
I thought only service worker need to be same origin. right ? |
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 |
@darrylsepeda to clarify: Your index.html is hosted at the same url as your website example.com/index.html and your other assets and webpack.public_path are cdn.com/assets/ Since index.html is at example.com (and not cdn.com) service worker is not caching the index.html correctly. |
@goldhand yes, thats right. And if we change the I thought we can add
|
Seems like a legitimate feature request, will think about an api for this unless you have a suggestion @darrylsepeda |
remove webpack public path for index.html goldhand#79
My solution still wrong.. I'm still trying to solve it |
Finally I found the workaround for this. I took out the compiled file from this plugin (located in
then I change the webpack.config.js file to import the sw-precache-webpack from the updated file: This is the workaround since I need it to be done a few days 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. |
So what will that look like?
Maybe that...? |
Well I know I've kinda hacked around this limitation temporarily by running a script that modifies the outputted file and replaces the Based on my assumption of your proposal above, I assume you are saying that you'd map the output from CommonChunks? In my use case I'm using the HtmlWebpackPlugin to generate my |
Is the only use for I think my suggestion was assuming we could reference the bundles that we wanted. Maybe using the filepath instead of the bundle as the key.
Example:
|
I mean my use cases so far have only needed the |
new SWPrecacheWebpackPlugin({
cacheId: 'fancy',
filename: 'service-worker.js',
// staticFileGlobs: ['dist/**/*.{js,html,css}'],
staticFileGlobs: ['dist/index.html'],
staticFileGlobsIgnorePatterns:[/\.map$/],
// minify: true, todo: close in deploy
mergeStaticsConfig:true,
stripPrefix: 'dist/'
}) |
@hodor-cn not alone, Your configuration will only output |
var precacheConfig = [
["//cdn.com/dist/css/app.8e50af800688ab69cf8da5b9a0ba053c.css","8e50af800688ab69cf8da5b9a0ba053c"],
["//cdn.com/dist/favicon.ico","c03bce8a8efaa811e1d6e32c88930d67"],
["//cdn.com/dist/index.html","4dabed415bcd6573e160078d66f551f7"],
["//cdn.com/dist/js/app.dbb6850538e27a599b90.js","013824ccba8972cf4798311695251ec3"],
["//cdn.com/dist/js/manifest.77931f469b723c419d9c.js","a51944eb0bc6250959940a6292bd6468"],
["//cdn.com/dist/js/vendor.5953645b5f4b4a670ad7.js","288999c45126fbfa47aceb17bafe6101"],
["//cdn.com/dist/manifest.json","f6c47fe2e29257b16d81835eb1c6fcff"],
["//cdn.com/dist/touch-icon-115.png","7d1135731b1e1202bba0e639f5f87faf"],
["index.html","4dabed415bcd6573e160078d66f551f7"]]; @lili21 works fine in my case, the |
Huh, I guess the |
@hodor-cn you're caching the index twice though with the same hash. |
@Psiablo i won't use the path |
@hodor-cn, well done, that looks good to me! 😄
Will add instructions to README and close this? Or is this still an issue? |
The purist in me says this is still an issue because in @hodor-cn's case you are caching or attempting to cache a duplicate that is never used or consumed.
|
I experience something similar. I am producing my index with the My current config:
How do I make sure the Basically, something like this would be nice:
|
Any solution for this case ? |
@erdoganoksuz I don't know if it helps your issue, but here is my working config:
|
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:
That
https://cdn.com/index.html
make theindex.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:
The text was updated successfully, but these errors were encountered: