【问题标题】:Refused to apply style because MIME type is not supported拒绝应用样式,因为不支持 MIME 类型
【发布时间】:2018-11-14 11:00:05
【问题描述】:

我不断收到一条错误消息,提示 MIME 类型 ('text/html') 不可执行或样式表 MIME 类型不受支持,并且启用了严格的 MIME 检查。

我的链接代码是

<link href="vendor/bootstrap/css/bootstrap.min.css" rel="stylesheet">

<!-- Custom styles for this template -->
<link href="css/heroic-features.css" rel="stylesheet">

<!-- Bootstrap core JavaScript -->
<script src="vendor/jquery/jquery.min.js"></script>
<script src="vendor/bootstrap/js/bootstrap.bundle.min.js"></script>

这就是模板的外观

然而,这就是它的样子

我需要将 text/html 更改为其他内容吗?

accepts: {
        "*": allTypes,
        text: "text/plain",
        html: "text/html",
        xml: "application/xml, text/xml",
        json: "application/json, text/javascript"
    }, 

Sinatra 告诉我这样做

但是我试过了还是不行

有什么我应该更改或添加到我的代码以使 css 正常工作的吗?

【问题讨论】:

标签: html css ruby mime-types mime


【解决方案1】:

我想您希望 text/css 用于您的样式表,application/javascript 用于 JS 文件。

根据 sinatra 文档,可以从请求级别访问传入的请求对象

get '/foo' do
  t = %w[text/css text/html application/javascript]
  request.accept              # ['text/html', '*/*']
  request.accept? 'text/xml'  # true
  request.preferred_type(t)   # 'text/html'
end

【讨论】:

    猜你喜欢
    • 2018-08-22
    • 2018-12-19
    • 2020-11-10
    • 2021-06-04
    • 2018-12-14
    • 2018-10-24
    • 1970-01-01
    • 1970-01-01
    • 2018-11-21
    相关资源
    最近更新 更多