Търсене в помощните статии

Избягвайте измамите при поддръжката. Никога няма да ви помолим да се обадите или изпратите SMS на телефонен номер или да споделите лична информация. Моля, докладвайте подозрителна активност на "Докладване за злоупотреба".

Научете повече

Stylesheet MIME type incorrectly interpreted as text/html since upgrading to v10

  • 5 отговора
  • 1 има този проблем
  • 1 изглед
  • Последен отговор от hobrob

more options

Hi,

I dynamically load a CSS file with some javascript like this:

domStylesheet = document.createElement('link');
domStylesheet.setAttribute('rel', 'stylesheet');
domStylesheet.setAttribute('type', 'text/css');
domStylesheet.setAttribute('href', 'http://my/css/url');

This has always worked until I upgraded to v10 (from v4.6), now I get the error 'The stylesheet http://my/css/url was not loaded because its MIME type, "text/html", is not "text/css"'.

Hi, I dynamically load a CSS file with some javascript like this:<br /> <br /> <pre><nowiki>domStylesheet = document.createElement('link'); domStylesheet.setAttribute('rel', 'stylesheet'); domStylesheet.setAttribute('type', 'text/css'); domStylesheet.setAttribute('href', 'http://my/css/url');</nowiki></pre> This has always worked until I upgraded to v10 (from v4.6), now I get the error 'The stylesheet http://my/css/url was not loaded because its MIME type, "text/html", is not "text/css"'.

Променено на от cor-el

Всички отговори (5)

more options

With which content type is the file send by that server if you open the file directly in a tab? Tools > Page Info > General

more options

type shows as text/html. Incidentally, I've tried loading the file in html markup with a <link> tag but get the same error.

more options

Stylesheet files should not be send as text/html, but should be send as text/css

more options

I've already tried changing my apache server config both with a TypesConfig file and explicitly with an AddTypes directive. But, looking at the HTTP headers in LiveHTTPHeaders, the server is sending them as text/html so I suppose the server is at fault. Maybe it always has been sending the wrong type and Firefox 10 no longer allows the type to be overridden on the client side?

more options

Solved it.

Configure Apache to handle .css files with php:
AddHandler application/x-httpd-php .css

Then set the content type with the php header function with this line at the top of the stylesheet file:
<?php header('Content-Type: text/css'); ?>

Променено на от cor-el