[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.javascript

Override mimetype when loading javascript dynamically?

meselfo

8/9/2014 1:43:00 PM

I'm trying to load some javascript dynamically using the code snippet below..

Unfortunately the server (which is outside my control) hosting the src is sending the script as MIME type "text/html" instead of "application/javascript" causing Chrome to fail with this message "Resource interpreted as Script but transferred with MIME type text/html:".

Is it possible on the client side to convince Chrome that it should consider it "application/javascript"?


var s = document.createElement("script");
s.type = "text/javascript";
s.src = "https://.....";
document.getElementsByTagName("head")[0].appendChild(s);
3 Answers

Thomas 'PointedEars' Lahn

8/9/2014 2:12:00 PM

0

Me Self wrote:
^^^^^^^

> I'm trying to load some javascript dynamically using the code snippet
> below.

There is no javascript; see my sig.

> Unfortunately the server (which is outside my control) hosting the src is
> sending the script as MIME type "text/html" instead of
> "application/javascript" causing Chrome to fail with this message
> "Resource interpreted as Script but transferred with MIME type
> text/html:".
>
> Is it possible on the client side to convince Chrome that it should
> consider it "application/javascript"?

No, you need to solve this server-side.

> var s = document.createElement("script");
> s.type = "text/javascript";
> s.src = "https://.....";
> document.getElementsByTagName("head")[0].appendChild(s);

Since the HTML5 API there is â??document.headâ? as a shortcut for
â??document.getElementsByTagName("head")[0]â?.

Please get a real name and do not post via the borken Google Groups.

--
PointedEars
FAQ: <http://PointedEars.... | SVN: <http://PointedEars.de...
Twitter: @PointedEars2 | ES Matrix: <http://PointedEars.de/es-...
Please do not Cc: me. / Bitte keine Kopien per E-Mail.

Andreas Bergmaier

8/10/2014 8:44:00 PM

0

[Someone] schrieb:

> Unfortunately the server (which is outside my control) hosting the src is sending the script as MIME type "text/html" instead of "application/javascript" causing Chrome to fail with this message "Resource interpreted as Script but transferred with MIME type text/html:".

That's not a fail, that's a mere *warning* that the server is configured
wrongly. As the message states, the script is still interpreted.

> Is it possible on the client side to convince Chrome that it should consider it "application/javascript"?

No. Make someone fix the server.

Regards,
Bergi

Denis McMahon

8/10/2014 9:58:00 PM

0

On Sat, 09 Aug 2014 06:43:04 -0700, Me Self wrote:

> I'm trying to load some javascript dynamically using the code snippet
> below.
>
> Unfortunately the server (which is outside my control) hosting the src
> is sending the script as MIME type "text/html" instead of
> "application/javascript" causing Chrome to fail with this message
> "Resource interpreted as Script but transferred with MIME type
> text/html:".
>
> Is it possible on the client side to convince Chrome that it should
> consider it "application/javascript"?

> var s = document.createElement("script");
> s.type = "text/javascript";
> s.src = "https://.....";
> document.getElementsByTagName("head")[0].appendChild(s);

What's the filetype of the src file? As has already been stated, the
issue appears to be in the server and there's nothing you can do in the
client to fix this one.

I would guess that either:

a) The resource is in a .htm[l] instead of a .js file; or
b) The resource is dynamically generated and the generating server side
script isn't setting the correct mime type.

Although it is also possible that an idiot has configured their server to
send *.js as "text/html" instead of "application/javascript"

--
Denis McMahon, denismfmcmahon@gmail.com