Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #25663 > unrolled thread

Override mimetype when loading javascript dynamically?

Started byMe Self <wmsopou@gmail.com>
First post2014-08-09 06:43 -0700
Last post2014-08-10 21:57 +0000
Articles 4 — 4 participants

Back to article view | Back to comp.lang.javascript


Contents

  Override mimetype when loading javascript dynamically? Me Self <wmsopou@gmail.com> - 2014-08-09 06:43 -0700
    Re: Override mimetype when loading javascript dynamically? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-08-09 16:11 +0200
    Re: Override mimetype when loading javascript dynamically? Andreas Bergmaier <andber93@web.de> - 2014-08-10 22:44 +0200
    Re: Override mimetype when loading javascript dynamically? Denis McMahon <denismfmcmahon@gmail.com> - 2014-08-10 21:57 +0000

#25663 — Override mimetype when loading javascript dynamically?

FromMe Self <wmsopou@gmail.com>
Date2014-08-09 06:43 -0700
SubjectOverride mimetype when loading javascript dynamically?
Message-ID<b8d21a27-0014-4054-886e-44157421f3d5@googlegroups.com>
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);

[toc] | [next] | [standalone]


#25665

FromThomas 'PointedEars' Lahn <PointedEars@web.de>
Date2014-08-09 16:11 +0200
Message-ID<1705878.HnaZ2UrlZN@PointedEars.de>
In reply to#25663
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.de/faq> | SVN: <http://PointedEars.de/wsvn/>
Twitter: @PointedEars2 | ES Matrix: <http://PointedEars.de/es-matrix>
Please do not Cc: me. / Bitte keine Kopien per E-Mail.

[toc] | [prev] | [next] | [standalone]


#25670

FromAndreas Bergmaier <andber93@web.de>
Date2014-08-10 22:44 +0200
Message-ID<ls8lir$al7$1@news.albasani.net>
In reply to#25663
[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

[toc] | [prev] | [next] | [standalone]


#25671

FromDenis McMahon <denismfmcmahon@gmail.com>
Date2014-08-10 21:57 +0000
Message-ID<ls8psh$v1$4@dont-email.me>
In reply to#25663
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

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.javascript


csiph-web