最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Angular Serving Assets as MIME ('texthtml') - Stack Overflow

programmeradmin0浏览0评论

Whenever we release a new version of our Angular App, the page will not load for users unless they clear their cache. It just keeps our loader spinning forever and is stuck on index.html.

In the chrome console there is an error saying that styles.css-hash has a MIME type of ('text/html') and that it is not a supported stylesheet MIME type. Note that I have also seen this happen with javascript files, including the main.js-hash from angular.

If we shift-click refresh or ctrl F5 to clear cache it loads the new styles.css-newhash and the page will load.

I have the stylesheet referenced in the angular.json (we are using angular 7) and not in the index.html.

Note most other questions similar to this suggest changing to relative pathing in the angular.json or to not reference the linked files in the index.html and to instead reference them in the angular-cli.json or the angular.json. Neither of these solutions worked.

We are not using the angular service worker.

Whenever we release a new version of our Angular App, the page will not load for users unless they clear their cache. It just keeps our loader spinning forever and is stuck on index.html.

In the chrome console there is an error saying that styles.css-hash has a MIME type of ('text/html') and that it is not a supported stylesheet MIME type. Note that I have also seen this happen with javascript files, including the main.js-hash from angular.

If we shift-click refresh or ctrl F5 to clear cache it loads the new styles.css-newhash and the page will load.

I have the stylesheet referenced in the angular.json (we are using angular 7) and not in the index.html.

Note most other questions similar to this suggest changing to relative pathing in the angular.json or to not reference the linked files in the index.html and to instead reference them in the angular-cli.json or the angular.json. Neither of these solutions worked.

We are not using the angular service worker.

Share Improve this question edited Sep 17, 2019 at 15:37 Nick Gallimore asked Sep 13, 2019 at 19:06 Nick GallimoreNick Gallimore 1,28315 silver badges37 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 5 +50

It's the webserver, not Angular. Since the #hash has changed, the previous file does not exist anymore.

The webserver is most likely showing a Page not found also known as 404 page, which has a mime of text/html, since it's a webpage.

You need to clear the cache on cache services like Cloudfront / Fastly / Varnish etc. if you have any.

You could also add no-cacheheaders to the page, but this is not remended, it's better to set a lesser cache time than standard, depending on your release / update frequency.

You should really remove the #hash part from production files, to not have this problem on production servers. Then the cached files will work until they are cleared, and the new ones will kick in.

As you mentioned it happens sometimes with your css and sometimes with your js files.

It might be that it's a problem with how your server is configured and your index.html file is being cached. On deploying a new version, you might be getting the old index.html file(unless user clears cache), and hence fetching the previous hash versions of css/js files, which of course are not there anymore.

So the web server responds with 404 and some Not Found content html type.

发布评论

评论列表(0)

  1. 暂无评论