-
Notifications
You must be signed in to change notification settings - Fork 388
MIME type ('text/html') is not executable, and strict MIME type checking is enabled. #180
Comments
The code that's responsible for populating the cache on service worker installation is about as basic as it gets: cache.add(new Request(cacheKey, {credentials: 'same-origin'})); That uses the Cache Storage API to make a network request and use the response of that request to populate our cache. Similarly, the code that's responsible for reading from the cache is just: cache.match(urlsToCacheKeys.get(url)); I don't think there's much room there for
Can you explain this in more detail? What's the HTML that you see? It might give a clue as to what's going on. You can also examine the contents of a cached resource by doing the following in the DevTools console: var url = '/path/to/resource.js';
fetch(url).then(r => r.text()).then(console.log); Try running that with |
Be sure that the |
How I fixed it: In the Webpack config I had to remove the navigateFallback as it was serving the old index.html file from the service worker: new SWPrecacheWebpackPlugin({
cacheId: 'someSecretString',
filename: 'sw.js',
dontCacheBustUrlsMatching: [/./],
staticFileGlobs: [path.join(__dirname, '../../build/') + '/**/*.{js,html,css,svg}'],
stripPrefix: path.join(__dirname, '../../build/'),
maximumFileSizeToCacheInBytes: 4194304,
navigateFallback: 'index.html', // <-- DELETED THIS LINE
}) Could it be that the index.html is one of the only files we have without a hash? it's not Now on every deploy there are no issues of serving the incorrect index.html file from the Service Worker since it's coming from the network now. But now index.html isn't being served when offline and it has to be from the network every time. Not really a win. I added
Yes, it is being re-run each time :) |
If you have a web app that uses the History API to modify the effective page's URL, you're going to need to use I think what's happening is along the lines of what you said; you're using
and as a result, when the service worker tries to refetch So my guess is that you may have HTTP caching enabled for |
@jeffposnick your solution seems to work! I changed I'll keep testing and close this issue once I feel confident it's working correctly. |
React & React Router with dynamic route bundling (loading JS chunks based on route change) Error:
Because we're using React Router (Browser history API) the user's page doesn't refresh on route update. This means the files initially loaded and updated by SW are out of sync. This breaks any dynamic chunking ability without refreshing the page to load the correct JS. Summary: Serving initial load from Service Worker, which has dynamic chunks of JS executed and saved in memory. But those dynamic routes don't exist anymore after Service Worker gets cache busted so updating route fails as it's pointing at files that don't exist anymore. Really struggling to solve this one. 😩 |
This sounds like a case where It should be easy to turn it off via an official option in the near future, but in the meantime, can you try making edits to your local The downside of removing |
Solves the issue. Yes, that's the behaviour we'll have to adapt because of the nature of dynamic route chunking. Thanks again for the tip. Look forward to the next release now 👍 |
Did you actually do I just want to confirm that you're not seeing, e.g., a failure to register the SW entirely due to a syntax error, which makes you think that the SW is behaving differently. |
You're right, my bad. My editor marked the Side question, maybe for a seperate issue, but what's the best way to minify sw-precache-webpack output file? currently all |
Okay, let me know if you see the behavior you expect when using a JavaScript comment. I don't tend to minify the generated service worker file, because given identical input, I don't trust all minifiers to produce identical output each time they're run. Any changes to the output file is enough to trigger the service worker update flow. This isn't a big deal, since the If you do have a minifier that will always produce the same output given the same input, then there shouldn't be any concerns. I don't have a specific recommendation, though. |
Working as expected, thanks again! |
Okay, great. I'll prioritize getting #122 added as an official option. |
FYI, release |
Sweet |
How to fix this error i am using ionic3 after run the ionic serve i got error? |
By default skipWaiting parameter is set to true, allowing newly registered service worker to bypass the `waiting` state, so all out of date cache entries from the previous service worker will be deleted. Because of async dynamic module loading we don't want that to happen, keeping a way of loading old chunks. The downside of removing skipWaiting is that newly deployed service worker code and caches won't become active until all existing tabs that have an older version of that service worker are closed, but that actually sounds we want exactly this behaviour. Related to GoogleChromeLabs/sw-precache#180 (comment)
By default skipWaiting parameter is set to true, allowing newly registered service worker to bypass the `waiting` state, so all out of date cache entries from the previous service worker will be deleted. Because of async dynamic module loading we don't want that to happen, keeping a way of loading old chunks. The downside of removing skipWaiting is that newly deployed service worker code and caches won't become active until all existing tabs that have an older version of that service worker are closed, but that actually sounds we want exactly this behaviour. Related to GoogleChromeLabs/sw-precache#180 (comment)
Hi everybody! I had the exact same problem but solved it differently. I'm sharing my solution to help everybody in the future. So I'm using workbox precaching, but when updating the scripts and deploying to the server, I forgot to increase the revision number for workbox.precaching.precacheAndRoute([
{ url: '/', revision: '2' },
...
]); |
Hi @brotzky and @jeffposnick , i am facing same issue, but we are using Angular 5 + Jenkins with nginx server setup. Can you tell me what all changes are required to solve issue in mine case? Thanks and regards |
I have faced with same this problem. |
This is the issue I'm getting
Refused to execute script from 'https:/www.example.com/app.jf813asdfd3t.js' because its MIME type ('text/html') is not executable, and strict MIME type checking is enabled.
Doing a hard refresh (CMD + SHIFT + R) skips the service worker cache and loads the newly deployed files without any issues. And then doing a regular refresh causes the error to come back.
My sw.js is not being cached and have nginx setup.
Deploying an update and refreshing pulls files from service worker, but they have the incorrect content-type.
Doing a hard refresh solves the issue
As you can see form the images, the files are being pulled from the same location, except that the service worker is pulling the incorrect content. When I go into the Chrome Develop Tool network tab and "preview" the content the service worker JS file contains only HTML and the hard reloaded one is actual JS.
I am using React with React Router.
This is my sw-precache webpack config:
My initial guess is that it's an issue with nginx, but asking if you guys have any other guesses.
The text was updated successfully, but these errors were encountered: