×Welcome to Stack Overflow! Visit your user page to set your name and email.
×You've earned the "Student" badge for Convert a webpage to an image (thumbnail). See your profile.
×Congrats, you've gained the privilege – flag posts and 4 other privileges learn more
Welcome back! If you found this question useful,
don't forget to vote both the question and the answers up.
close this message

In FF and all, my javascript works fine. But in Chrome it gives this message: "Resource interpreted as script but transferred with MIME type text/plain."

I have checked all the script tags and they all have the MIME type="text/javascript". It even says so with jquery and jquery ui. What's up with Chrome?

What's the problem and the fix for this? Is it something I have to change in the 'options' of the browser or is it from the server, or do I have to tweak my code?

I've been trying to solve it for 2 weeks and I can't find any solution. Please advise me on this.

link|edit|flag

2 upvote
 flag
Some code would be helpful. Never blame the compiler (browser) first no matter how tempting it is because you'll almost always be mistaken. – msw Aug 12 '10 at 12:10
  upvote
 flag
Voting on some answers wouldn't hurt either, in addition to accepting them. – msw Aug 12 '10 at 12:11
3 upvote
 flag
8 questions, zero accepted answers. – Scott M. Aug 12 '10 at 12:13
2 upvote
 flag
Ok ok, I got the message... no need to say more... I didn't know the rules of this site, that's all. And I'am working where I can't really stay too long on the internet and play about, so understand the situation of someone before making assumptions next time, OK! – Shaoz Aug 13 '10 at 9:06
  upvote
 flag
as a matter of curiosity, are you using html5? – bollo Aug 26 '11 at 8:27

protected by SLaks May 1 at 14:49

This question is protected to prevent "thanks!", "me too!", or spam answers by new users. To answer it, you must have earned at least 10 reputation on this site.

8 Answers

up vote 40 down vote accepted

It means that the server is sending an Javascript HTTP response with content-type:text/plain.

You should configure the server to send the Javascript responses with content-type:application/x-javascript.

link|edit|flag
1 upvote
 flag
I'm using Weblogic Server 11g, but I don't know where I can configure the MIME in it. Please, can you show me the way? – Shaoz Aug 12 '10 at 13:36
2 upvote
 flag
I have no idea; Google it. Also, look at the requests in Fiddler. – SLaks Aug 12 '10 at 13:51
1 upvote
 flag
Thanks for your help, you've given me a head start. – Shaoz Aug 13 '10 at 10:58

This has nothing to do with jQuery or any quirk of client-side script code. It is a server-side issue: The server(-side application) is not sending the expected HTTP Content-Type header field value for the client-side script resource. This happens if the Web server is insufficiently configured, misconfigured, or a server-side application (e. g., PHP) is generating the client-side script resource.

Proper MIME media types for ECMAScript implementations like JavaScript include:

  • text/javascript (registered as obsolete, not deprecated; but still valid, and supported best)
  • text/ecmascript (registered as obsolete, not deprecated; but still valid)
  • application/javascript
  • application/ecmascript

They do not include application/x-javascript, as the MIME media types listed above are the ones registered in the standards tree by now (so there is no need, and there should be no want, to use experimental ones anymore). Cf. RFC 4329, "Scripting Media Types" (2005 CE) and my Test Case: Support for Scripting Media Types.

One solution is to configure the server if possible, as already recommended. For Apache, this can be as simple as adding the directive

AddType text/javascript .js

(see the Apache HTTP Server documentation for details).

But if the client-side script resource is generated by a server-side application, like PHP, then it is necessary to set the Content-Type header field value explicitly, as the default is likely text/html:

<?php
  header('Content-Type: text/javascript; charset=UTF-8');
  // ...
?>

(That and similar statements must come before any other output – see the PHP manual –, else the HTTP message body is considered to have begun already and it is too late to send more header fields.)

Server-side generation can happen easily to a client-side script resource even if you have plain .js files on the server, if comments are removed from them as they are served, if they are all packed into one large response (to reduce the number of requests, which is more efficient), or they are minimized by the server-side application in any other way.

link|edit|flag

1) Make sure your weblogic.xml file is free of errors

like this one:

    <?xml version = '1.0' encoding = 'windows-1252'?>
<weblogic-web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                  xsi:schemaLocation="http://www.bea.com/ns/weblogic/weblogic-web-app http://www.bea.com/ns/weblogic/weblogic-web-app/1.0/weblogic-web-app.xsd"
                  xmlns="http://www.bea.com/ns/weblogic/weblogic-web-app">
    <container-descriptor>
        <prefer-web-inf-classes>true</prefer-web-inf-classes>
    </container-descriptor>
    <context-root>MyWebApp</context-root>
</weblogic-web-app>

2) Add a mime type for javascript to your web.xml file:

    ...
        </servlet-mapping>

        <mime-mapping>    
            <extension>js</extension>        
            <mime-type>application/javascript</mime-type>        
        </mime-mapping>

        <welcome-file-list>
    ...

application/javascript is currently the only valid mime-type; others like text/javascript have been deprecated

3) You may need to clear up your browser cache or hit CTRL-F5

link|edit|flag

FYI I get the same error on any page that loads Google Analytics. I've been ignoring it -- I didn't think it was a big deal.

link|edit|flag
  upvote
 flag
Same here, analytics does it. Minor annoyance. – Tchalvak Jul 26 '11 at 20:13
  upvote
 flag
@Tchalvak - Does that mean it's not to be worried about? I've been getting the same error with ga.js. Is there a solution, or is just something one has to live with? – stefmikhail Oct 2 '11 at 20:46
  upvote
 flag
Just means that the GA server is serving stuff with a mime-type that isn't a javascript mime-type, or the browser doesn't detect as javascript mime-type, certainly not something to be worried about. – Tchalvak Oct 2 '11 at 20:55

I was having the same issue when trying to change a background images in a array through javascript (jQuery in this case).

Anyway.

Instead of this:

m.setStyle('background-image','url(/templates/site/images/style5/'+backgs[i]+')')

do this:

eval("m.setStyle('background-image','url(/templates/site/images/style5/'+backgs[i]+')')");

Chrome javascript gets screwed when trying to parse a variable inside an element structured with ' . In my case it stopped just before the image array being inserted. Instead of parsing the image url + image name (inside the array), it was parsing just the image url.

You probably need to search inside the code and see where it happens. FF, IE and all other don't have this problem.

link|edit|flag
1 upvote
 flag
Don't use eval if you can help it: javascripttoolbox.com/bestpractices/#eval – 5arx Mar 19 at 17:02

I had this problem and I figured out how to fix it.

It happens when the style (CSS) file is in a different encoding from the PHP file that references the .css file

For example, using jQuery.js in Unix encoding and using index.php in UTF-8 will cause this problem so you have to make them both UTF-8 or any other encoding as long as it the same.

link|edit|flag

PHP at the top of your script->

//Add the JS Header:
header("content-type:application/x-javascript");
link|edit|flag

In your apache's httpd.conf, just add such a line:

AddType application/x-javascript .js
link|edit|flag

Your Answer

  • Images are exactly like links, but they have an exclamation point in front of them:

    ![a busy cat](http://sstatic.net/stackoverflow/img/error-lolcat-problemz.jpg)
    ![two muppets][1]
    
     [1]: http://i.imgur.com/I5DFV.jpg "tooltip"
    

    The word in square brackets is the alt text, which gets displayed if the browser can't show the image. Be sure to include meaningful alt text for screen-reading software.

    Be sure to use text styling sparingly; only where it helps readability.

    *This is italicized*, and so
    is _this_.
    
    **This is bold**, just like __this__.
    
    You can ***combine*** them
    if you ___really have to___.
    

    To break your text into sections, you can use headers:

    A Large Header
    ==============
    
    Smaller Subheader
    -----------------
    

    Use hash marks if you need several levels of headers:

    # Header 1 #
    ## Header 2 ##
    ### Header 3 ###
    

    Both bulleted and numbered lists are possible:

    - Use a minus sign for a bullet
    + Or plus sign
    * Or an asterisk
    
    1. Numbered lists are easy
    2. Markdown keeps track of
       the numbers for you
    7. So this will be item 3.
    
    1. Lists in a list item:
        - Indented four spaces.
            * indented eight spaces.
        - Four spaces again.
    2.  You can have multiple
        paragraphs in a list items.
     
        Just be sure to indent.
    
    > Create a blockquote by
    > prepending “>” to each line.
    >
    > Other formatting also works here, e.g.
    >
    > 1. Lists or
    > 2. Headings:
    >
    > ## Quoted Heading ##
                

    You can even put blockquotes in blockquotes:

    > A standard blockquote is indented
    > > A nested blockquote is indented more
    > > > > You can nest to any depth.
    

    To create code blocks or other preformatted text, indent by four spaces:

        This will be displayed in a monospaced font. The first four spaces
        will be stripped off, but all other whitespace will be preserved.
        
        Markdown and HTML are turned off in code blocks:
        <i>This is not italic</i>, and [this is not a link](http://example.com)
    

    To create not a block, but an inline code span, use backticks:

    Press the `<Tab>` key, then type a `$`.
    

    If you want to have a preformatted block within a list, indent by eight spaces:

    1. This is normal text.
    2. So is this, but now follows a code block:
     
            Skip a line and indent eight spaces.
            That's four spaces for the list
            and four to trigger the code block.
    

    If you need to do something that Markdown can't handle, use HTML. Note that we only support a very strict subset of HTML!

    Strikethrough humor is <strike>funny</strike>.
    

    Markdown is smart enough not to mangle your span-level HTML:

    <b>Markdown works *fine* in here.</b>
    

    Block-level HTML elements have a few restrictions:

    1. They must be separated from surrounding text by blank lines.
    2. The begin and end tags of the outermost block element must not be indented.
    3. Markdown can't be used within HTML blocks.

    <pre>
        You can <em>not</em> use Markdown in here.
    </pre>
    
 

Not the answer you're looking for? Browse other questions tagged or ask your own question.