我能将CSS样式表托管在Pastebin上吗?

4

这更多是出于好奇,但是否可以在Pastebin上保存样式表并在HTML文档中加载它?我尝试按照通常链接样式表的方式来做,但没有成功。这是我使用的测试代码:

<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>

我正在尝试使用的代码保存在http://pastebin.com/0dY5eBga
1个回答

4
你不能以这种方式从pastebin导入样式表,即使使用原始url,因为pastebin服务器在HTTP响应中设置了“Content-Type”头为“text/plain”。这将防止文件被正确解释为CSS样式表。
例如,Chrome将会给出以下错误:
“Resource interpreted as Script but transferred with MIME type text/plain”
然后它将拒绝应用你的样式。
请参见以下MDN文章,了解有关CSS文件不正确的MIME类型的详细信息 - 许多浏览器会阻止具有不正确MIME类型的资源: CSS文件的不正确MIME类型 配置服务器MIME类型
以下是有关CSS无法在Pastebin中链接的实时示例,因为服务器未使用"text/css" MIME类型发送它:

<link href="http://pastebin.com/raw.php?i=0dY5eBga" rel="stylesheet"/>

<p>This text is not red.</p>


有没有像https://raw.githack.com这样的代理,但是用于pastebin? - idontknow

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接