Styles from countless files are not used

We have a website that uses .less files (pre-compiler dotless was installed using nuget), however formatless files are not treated as css files.

When trying to browse the website in firefox, the console throws the following error: The stylesheet http: //website/css/init.less was not loaded because its MIME type "application / octet-stream" is not "text / css".

Our aimless file is trying to import more files:

@import "imports";
..

      

But even replacing this text with css code, the styles are still not applied. But if I go to this file in Visual Studio, it displays all the css from the imported files.

+3


source to share


1 answer


If you are using the dotLess handler to process and serve your files .less

on the fly (which is great for debugging, but you might think about pre-compiling for release), you need to make sure you ship them with the correct type as well.

You can do this either at the server level in IIS Admin (if you will probably be using this for multiple sites on the machine) or at the local site level via web.config - note that you cannot do both, IIS will complain about multiple entries for the file extension.

To do this in the web.config file, <configuration><system.webServer>

add the following elements to the element:

<staticContent>
  <mimeMap fileExtension=".less" mimeType="text/css" />
</staticContent>

      



Obviously if you already have mimemap entries, just add the mimemap in there.

This ensures that IIS asserts that the files .less

that were rendered by the handler were CSS and not the default application/octect-stream

.

If that doesn't yet serve them as processed, there are a few more things you need to check:

  • Make sure the handler is correctly registered in the <system.webserver><handlers>

    and sections <system.web><httpHandlers>

    (depending on the version of IIS you are using:
    <add name="dotless" path="*.less" verb="GET" type="dotless.Core.LessCssHttpHandler,dotless.Core" resourceType="File" preCondition="" />


    and
    <add path="*.less" verb="GET" type="dotless.Core.LessCssHttpHandler, dotless.Core" />

  • Make sure IIS is configured to send all requests through the ASP.NET handlers configured in step 1. By default, files .less

    are likely to be treated as "static files" and will only be processed using the StaticFileModule.
    enter image description here
+2


source







All Articles