Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the MIME-Type of TypeScript?

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?

I already looked up the language specification but I didn't find any clue.

like image 459
Zwirbelbart Avatar asked Nov 03 '12 21:11

Zwirbelbart


People also ask

What is a MIME file type?

Multipurpose Internet Mail Extension or MIME is an internet standard, encoded file format used by email programs. The mime format contains 8-bit encoded data instead of commonly used 7-bit encoding for sending email. Thus, MIME files can contain file attachments and richer character sets other than ASCII.

How do I know my MIME type?

For detecting MIME-types, use the aptly named "mimetype" command. It has a number of options for formatting the output, it even has an option for backward compatibility to "file". But most of all, it accepts input not only as file, but also via stdin/pipe, so you can avoid temporary files when processing streams.

Is MIME type same as file type?

Whereas file extensions are commonly used for your OS to decide what program to open a file with, Mime types are used by your browser to decide how to present some data (or the server on how to interpret received data). Both are optional but it's a good practice to have an agreement.


3 Answers

It would be good to know why you want to serve TypeScript files.

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

If you still want to serve .ts files via IIS, you can still add a custom mime-type in 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/.

So, depending on your usage, you might choose text/x.typescript or text/prs.typescript.

like image 130
devio Avatar answered Oct 25 '22 13:10

devio


Stick this in your web.config;

<configuration>
    ...
    <system.webServer>
        <staticContent>
            <mimeMap fileExtension=".ts" mimeType="application/x-typescript" />
        </staticContent>
    </system.webServer>
</configuration>
like image 30
Steve Cooper Avatar answered Oct 25 '22 13:10

Steve Cooper


Deno uses application/typescript to serve TypeScript files, allowing you to run them with:

deno run "https://example.com/file.ts"
like image 2
Avestura Avatar answered Oct 25 '22 14:10

Avestura