DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones AWS Cloud
by AWS Developer Relations
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones
AWS Cloud
by AWS Developer Relations
  1. DZone
  2. Coding
  3. JavaScript
  4. What is the correct media type for JavaScript source code?

What is the correct media type for JavaScript source code?

Axel Rauschmayer user avatar by
Axel Rauschmayer
·
Aug. 16, 11 · Interview
Like (0)
Save
Tweet
Share
8.02K Views

Join the DZone community and get the full member experience.

Join For Free
Question: What media type should you use for JavaScript source code? Answer [via Brendan Eich] and explanations after the break.

The correct JavaScript media type

There are many JavaScript media types in use. Examples:
    application/ecmascript
    application/javascript
    application/x-ecmascript
    application/x-javascript
    text/ecmascript
    text/javascript
    text/javascript1.0
    text/javascript1.1
    text/javascript1.2
    text/javascript1.3
    text/javascript1.4
    text/javascript1.5
    text/jscript
    text/livescript
    text/x-ecmascript
    text/x-javascript
Which one of those is correct? RFC 4329 has the answer:
Use of the “text” top-level type for this kind of content is known to be problematic. This document thus defines text/javascript and text/ecmascript but marks them as “obsolete”. Use of experimental and unregistered media types, as listed in part above, is discouraged. The media types,
  • application/javascript
  • application/ecmascript
which are also defined in this document, are intended for common use and should be used instead.
However: While text/javascript is considered obsolete, it might still be necessary to use it if you want your code to run on Internet Explorer 8. Quoting machineghost on Stack Overflow [via Gezim Hoxha]:
Moral of the story: if you want IE8 to work DO NOT use "application/javascript" for your JS files' MIME type [a.k.a. media type].

Uses of the media type

The (internet) media type of JavaScript source code is mainly needed in two cases:
  • When serving code via a web server.
  • As the value of an optional attribute of the script tag:
        <script type="application/javascript">
            ...
        </script>
    
    This scheme might be extended in the future to switch on support for ECMAScript.next (which will probably eventually be called ECMAScript 6):
        <script type="application/javascript;version=6">
            ...
        </script>
    

 

From http://www.2ality.com/2011/08/javascript-media-type.html

Media type Media (communication) JavaScript

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • Accelerating Enterprise Software Delivery Through Automated Release Processes in Scaled Agile Framework (SAFe)
  • How To Build an Effective CI/CD Pipeline
  • Keep Your Application Secrets Secret
  • A Beginner's Guide to Infrastructure as Code

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: