Search code examples
htmlcsspastebin

Can I host a CSS stylesheet on Pastebin?


This is more out of curiosity than anything, but is it possible to save a stylesheet on Pastebin and load it in an HTML document? I tried to do it the way you'd normally link a stylesheet, but it didn't work. Here's the test code I used:

<html>
    <head>
    <title>Test</title>
    <link rel="stylesheet" type="text/css" 
    href="http://pastebin.com/0dY5eBga" />
    </head>

    <body>
    <p>This is a test. Will it work? Probably not.</p>
    </body>
</html>

The code I'm trying to use is saved at http://pastebin.com/0dY5eBga.


Solution

  • You cannot import stylesheets from pastebin in this way, even using the raw url, because the pastebin server sets a Content-Type header of text/plain on the HTTP response. This will prevent the file from being properly interpreted as a CSS stylesheet.

    For instance, Chrome will give the following error:

    Resource interpreted as Script but transferred with MIME type text/plain

    And then it will refuse to apply your styles.

    Please see the following MDN articles for details about incorrect MIME types on CSS files - many browsers block resources with incorrect MIME types:
    Incorrect MIME Type for CSS Files
    Configuring Server MIME Types


    Here is a live example of CSS not working when linked from Pastebin, because the server does not send it with the text/css MIME type:

    <link href="http://pastebin.com/raw.php?i=0dY5eBga" rel="stylesheet"/>
    
    <p>This text is not red.</p>