CSS file blocked: MIME type mismatch (X-Content-Type-Options: nosniff)
I just ran into the same issue. It appears to be a quirk of Express that can manifest itself for a few different reasons, judging by the number of hits from searching the web for "nodejs express css mime type".
Despite the type="text/css"
attribute we put in our <link
elements, Express is returning the CSS file as
Content-Type: "text/html; charset=utf-8"
whereas it really should be returning it as
Content-Type: "text/css"
For me, the quick and dirty workaround was to simply remove the rel=
attribute, i.e., change
<link rel="stylesheet" type="text/css" href="styles.css">
to
<link type="text/css" href="styles.css">
Testing confirmed that the CSS file was downloaded and the styles did actually work, and that was good enough for my purposes.
Resource was blocked due to MIME type mismatch using pug and node
This is because you are using relative url's in your attributes.
Replace this:
link(href='img/favicon.png' rel='icon')
With this:
link(href='/img/favicon.png' rel='icon')
To explain this further, when you are viewing /employee
then the relative link at img/123.jpg
is correctly resolved as /img/123.jpg
. However, as soon as you go to the url /employee/joeblow
then the relative link is looking for /employee/img/123.jpg
. You'll be able to confirm this by opening Developer Tools in your browser then looking at the requests made in the Network tab.
Adding the slash at the front of all img
elements will ensure that they look for the images in the correct folder, the one off the root (/
).
The bootstrap mime-type error must be coming from one of the libraries that is loading correctly but not finding a dependency due to the issue described above.
Related Topics
How to Escape an Ampersand in a JavaScript String So That the Page Will Validate Strict
Javascript, Track Iframes Redirecting Top Window
Automatically Refreshing Page Every 60 Seconds Using JavaScript
Jquery Remove Special Characters from String and More
React-Select:Get Default Value in React-Select
Innerhtml Inserts Only [Object Htmldivelement]
Check If Value Select2 Is Null
Can We Insert JavaScript into Any Webpage Loaded in the Browser
How to Remove a File from the Filelist
How to Count Duplicate Value in an Array in JavaScript
How to Add Data Dynamically to Mat-Table Datasource
How to Convert Date Format from Dd.Mm.Yyyy to Dd/Mm/Yyyy in JavaScript
Deselect All Options in Multiple Select With 1 Option
Usestate Hook Not Updating a Value
How to Change Background Color of a Row on Checkbox Selection