Edge警告说&quot“ content-type'标题Charset值应为UTF-8”。

发布于 2025-01-31 22:27:35 字数 903 浏览 6 评论 0 原文

Edge Dev-Tools很好,但是我只是不知道如何解决一些错误。

显然,index.html和两个SVG文件有问题。一个SVG使用IMG-TAG,另一个SVG使用CSS。

我尝试了将其添加到SVG中的其他方面:

<?xml version="1.0" encoding="utf-8"?>

对于HTML文件和SVG文件,我也尝试了其中的一种变体

<meta charset="utf-8">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">

,最后一个,为什么Firefox是否不支持功能,为什么Edge会关心?

”在此处输入图像描述“

src =“ https://i.sstatic.net/7mz0t.png” alt =“在此处输入图像说明”>

Edge dev-tools is nice helping out, but some errors I just don't know how to fix.

Apparently there's something wrong with the index.html and two SVG-files. One SVG uses img-tag and the other SVG uses CSS.

I tried among other things adding this to the SVG:

<?xml version="1.0" encoding="utf-8"?>

And for both the html-file and svg-files I tried variations of these

<meta charset="utf-8">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">

Also, the last one, why would Edge care if firefox doesn't support a feature?
'content-type' header charset value should be utf-8

enter image description here

enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

披肩女神 2025-02-07 22:27:35

我也花了很长时间试图制定此警告信息。

通过检查Microsoft Edge的DevTools中的“网络”选项卡,我发现仅在从缓存中检索数据时,即从文件中加载数据时才显示警告消息。

我不知道这一点的含义。但是,知道我的标题实际上正确编写了,这让您感到欣慰。

I too spent ages trying to work out this Warning message.

By examining the Network tab in Microsoft Edge's DevTools, I discovered that the Warning message is shown only when data is retrieved from cache, not when it is loaded from file.

I do not know the implications of this. But it is a relief to know that my headers are in fact written correctly.

明明#如月 2025-02-07 22:27:35

错误显示了从服务器发送的实际文件上显示的,HTTP标头 content-type 应另外设置 charset 值。

要这样做取决于您正在使用的后端服务器。

c#aspnetcore(kestrel)中的示例,在服务静态文件时,您可以使用这些额外的映射来修改内容类型提供商:

// File: Program.cs or Startup.cs
using Microsoft.AspNetCore.StaticFiles;
...
IApplicationBuilder app;

var contentTypeProvider = new FileExtensionContentTypeProvider();
var mappings = contentTypeProvider.Mappings;

// Modify mappings:
mappings[".htm"]  += "; charset=utf-8";
mappings[".html"] += "; charset=utf-8";
mappings[".js"]   += "; charset=utf-8";
mappings[".svg"]  += "; charset=utf-8";
...
app.UseStaticFiles(new StaticFileOptions()
{
  ContentTypeProvider = contentTypeProvider
});

The error displays that on the actual file that is sent from the server, that the http header Content-Type should additionally set the charset value.

To do this depends on which backend server you are using.

Example in C# AspNetCore (kestrel), when serving static files you could modify the content type provider with these extra mappings:

// File: Program.cs or Startup.cs
using Microsoft.AspNetCore.StaticFiles;
...
IApplicationBuilder app;

var contentTypeProvider = new FileExtensionContentTypeProvider();
var mappings = contentTypeProvider.Mappings;

// Modify mappings:
mappings[".htm"]  += "; charset=utf-8";
mappings[".html"] += "; charset=utf-8";
mappings[".js"]   += "; charset=utf-8";
mappings[".svg"]  += "; charset=utf-8";
...
app.UseStaticFiles(new StaticFileOptions()
{
  ContentTypeProvider = contentTypeProvider
});
那小子欠揍 2025-02-07 22:27:35

我正面临同一问题。

浏览器只希望您定义 Mime Type

    <link rel="stylesheet" href="styles.css" type="text/css">
    <script src="index.js" type="text/javascript"></script>
    <img src="icon.svg" type="image/svg+xml"></img>

I was facing the same issue

The browser just wants you to define the mime type

    <link rel="stylesheet" href="styles.css" type="text/css">
    <script src="index.js" type="text/javascript"></script>
    <img src="icon.svg" type="image/svg+xml"></img>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文