TypeScript 的 MIME 类型是什么?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13213787/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What's the MIME-Type of TypeScript?
提问by Zwirbelbart
I want my IIS to correctly display .ts files, is there any MIME-Type for TypeScript? text/javascript or similar may also work, but are there specifications for that?
我希望我的 IIS 正确显示 .ts 文件,TypeScript 是否有任何 MIME 类型?text/javascript 或类似的也可以工作,但有规范吗?
I already looked up the language specificationbut I didn't find any clue.
我已经查找了语言规范,但没有找到任何线索。
回答by devio
It would be good to know whyyou want to serve TypeScript files.
最好知道为什么要提供 TypeScript 文件。
As far as I understand, TypeScript is used to compile to Javascript, which is then executed in a browser. Currently, there is no native support for TypeScript (correct me if I'm wrong).
据我了解,TypeScript 用于编译成 Javascript,然后在浏览器中执行。目前,没有对 TypeScript 的原生支持(如果我错了,请纠正我)。
If you still want to serve .ts files via IIS, you can still add a custom mime-typein IIS Admin associated with .ts. The standard defines the prefixes x.
, vnd.
and prs.
, and the vnd. prefix is also listed in the standardized mime types text/and application/.
如果您仍想通过 IIS 提供 .ts 文件,您仍然可以在与 .ts 关联的 IIS Admin 中添加自定义 MIME 类型。该标准定义了前缀x.
、vnd.
和prs.
和 vnd。前缀也在标准化 mime 类型text/和application/ 中列出。
So, depending on your usage, you might choose text/x.typescript
or text/prs.typescript
.
因此,根据您的使用情况,您可以选择text/x.typescript
或text/prs.typescript
。
回答by Steve Cooper
Stick this in your web.config;
把它放在你的 web.config 中;
<configuration>
...
<system.webServer>
<staticContent>
<mimeMap fileExtension=".ts" mimeType="application/x-typescript" />
</staticContent>
</system.webServer>
</configuration>
回答by Simon_Weaver
You may also need to comment out TypeScriptAssetHandler
which converts .ts files to javascript.
您可能还需要注释掉TypeScriptAssetHandler
哪些将 .ts 文件转换为 javascript。
<handlers>
<!--<add name="TypeScriptAssetHandler" path="*.ts" verb="GET" type="BundleTransformer.TypeScript.HttpHandlers.TypeScriptAssetHandler, BundleTransformer.TypeScript" resourceType="File" preCondition="" />-->
</handlers>
You may end up with errors like this if you have this handler defined
如果你定义了这个处理程序,你最终可能会遇到这样的错误
[HttpException (0x80004005): During the output text content of processed asset an unknown error has occurred.
See more details:
Exception has been thrown by the target of an invocation.]
回答by geekdenz
Using Apache 2 I simply set the MIME Type to text/plain. This solved my problem where I was getting weird results as in the MIME Type reported was some video format.
使用 Apache 2 我只需将 MIME 类型设置为 text/plain。这解决了我得到奇怪结果的问题,因为报告的 MIME 类型是某种视频格式。
You can achieve this with the following in your Apache 2 configuration:
您可以在 Apache 2 配置中使用以下内容来实现此目的:
<filesMatch "\.(html|htm|js|css|ts|ts!transpiled)$">
FileETag None
<ifModule mod_headers.c>
Header unset ETag
Header set Cache-Control "max-age=0, no-cache, no-store, must-revalidate"
Header set Pragma "no-cache"
Header set Expires "Wed, 11 Jan 1984 05:00:00 GMT"
</ifModule>
</filesMatch>
AddType text/plain ts