跳到正文
Skillpedia
部署与云(DevOps)75k · #2938

mime-type

它能做什么

这项技能检查服务器随 HTML、CSS、JavaScript、图片和字体一起发送的内容类型标头。适用于管理 Web 服务器或排查页面资源故障的人。

适用场景

  • ✓当你请智能体检查服务器是否发送了正确的文件类型的时候。
  • ✓当样式表或脚本无法加载,而你怀疑内容类型有误的时候。
  • ✓当你设置新的托管或新框架,并想确认其标头正确的时候。

技能链接

https://github.com/thedaviddias/Front-End-Checklist/blob/main/skills/mime-type/SKILL.md

复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。

使用方法

最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。

可直接粘贴的消息

请用这个技能帮我:https://github.com/thedaviddias/Front-End-Checklist/blob/main/skills/mime-type/SKILL.md 阅读该链接中的 SKILL.md 文件,并在我的任务中按照它的说明来做。
想让你的 AI 自己找到这样的技能吗?安装免费的 Skillpedia MCP:只需一行,每次任务前它都会在 15,000+ 个技能中搜索。1 分钟完成安装 →

可以这样问 AI

“我网站上的 CSS 没有加载。请帮我检查服务器是否发送了正确的内容类型?”

每周 5 个新技能,1 分钟读完。

工作原理

智能体会检查关键页面和链接文件的响应标头,并与预期类型(例如样式表的 text/css)进行比较。如果不匹配,它会建议修改服务器设置。

技术内容(原始 SKILL.md)

作者在 GitHub 上的英文原文。

MIME Type Validation

Incorrect MIME types cause browsers to block stylesheets and scripts (MIME sniffing is disabled by X-Content-Type-Options: nosniff), breaking page rendering and signalling poor site quality to crawlers.

Quick Reference

  • The Content-Type header must match the actual file type being served
  • HTML pages must be served as text/html; charset=utf-8
  • CSS files must be served as text/css and JavaScript as text/javascript
  • Incorrect MIME types cause browsers to block or mishandle resources

Check

For key pages and their linked resources, inspect the HTTP Content-Type response header. Verify HTML responses use text/html; charset=utf-8, CSS uses text/css, JS uses text/javascript, and images use image/jpeg, image/png, etc.

Fix

Update your server configuration to serve each file type with its correct MIME type. Set X-Content-Type-Options: nosniff to prevent browsers from guessing content types. In Next.js and similar frameworks, configure headers in next.config.js.

Explain

The Content-Type header tells browsers and crawlers what kind of content is being sent. When it mismatches the actual file type, browsers either block the resource or render it incorrectly—CSS served as text/plain won't be applied, and JavaScript served as text/html may be blocked by strict MIME checking.

Code Review

For HTML, CSS, and JS assets, check the Content-Type response header. Verify HTML responses include 'charset=utf-8'. Check that X-Content-Type-Options: nosniff is set. Flag any resource returning Content-Type: text/html that is not an HTML page. Check for missing charset declarations on text responses.


For full implementation details, code examples, and framework-specific guidance, see references/rule.md.

Rule page: https://frontendchecklist.io/rules/seo/mime-type

常见问题

内容类型错误会怎样?

浏览器可能会阻止该文件,或错误地显示它,因此样式表可能完全无法生效。

nosniff 是做什么的?

X-Content-Type-Options 标头告诉浏览器不要猜测类型,而是依据服务器发送的值。

在 Next.js 中如何设置?

这项技能建议在 next.config.js 文件中配置标头。

详情

作者的原始描述

Use when auditing server configuration or diagnosing broken resources. Applies to any web server serving HTML, CSS, JS, images, fonts, or other static assets.

repo: thedaviddias/Front-End-Checklist

热度

GitHub 星标
75k
排名
#2938
许可证
MIT
更新时间
2026/10/31

这个技能有用吗?

0

登录 后即可投票。

评论

  • …

同一仓库的更多技能

相似技能