Resource interpreted as document but transferred with MIME type text/css

前端 未结 2 1648
一向
一向 2020-12-09 14:38

Resource interpreted as document but transferred with MIME type text/css

This is the error that\'s showing up in Google Chrome Inspector.

The

2条回答
  •  暖寄归人
    2020-12-09 15:25

    I get the same error and I think I know why. If you look at your request headers you see they include:

    Accept:application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,/;q=0.5

    They especially do NOT include "text/css". So Chrome is telling the server it will NOT accept a response of type "text/css" and when it gets such anyway it reports that happening on its console.

    When I ordinarily include a CSS-stylesheet into an html-page the error-message does not show up because in those cases Chrome request-header says:

    Accept: text/css
    

    But if I try to set

    iframe.src = someCssFile.css
    

    I get the message. So it gives me the clue that I'm trying to load CSS to somewhere where it is not expected. It does load it, but console gives me the message.

    And really it is not an error, it is a Warning, that's what Chrome calls it. A Warning. But I agree it's good to know what's causing it.

    I don't think there's any way to explicitly control the request-headers Chrome sends to the server. Browsers just interpret HTML and based on that come up with the headers they send.

提交回复
热议问题