Page MenuHomePhabricator

Geo lookup causes mime type errors in Chrome
Closed, ResolvedPublic

Description

When loading http://meta.wikimedia.org with

Google Chrome 6.0.472.59
OS: OS X

I can see the following with the dev tools browser

Resource interpreted as script but transferred with MIME type application/json http://geoiplookup.wikimedia.org/?283u


Version: unspecified
Severity: enhancement
URL: http://meta.wikimedia.org

Details

Reference
bz25346

Event Timeline

bzimport raised the priority of this task from to Medium.Nov 21 2014, 11:20 PM
bzimport set Reference to bz25346.

CC Mark, who setup geoiplookup IIRC. The problem is that geoiplookup is returning a Content-Type: application/json header; this should be text/javascript .

What's interesting is the we changed it to application/json because that's what Safari was expecting.

application/json is the correct MIME type for json (and indeed it seems that Chrome is the only browser complaining in this case). However, the geoIP JSON is not technically "well-formed" JSON, so this may be why Chrome is complaining. The geoIP JSON may not constitute "well-formed" Javascript either, so changing it to text/javascript may cause Safari to complain (as Safari seems to be sensitive to this). I guess what we need to do is test both MIME types in both browsers and see what we get.

ticket collision:

It's not JSON though is it ? I mean it has "Geo =" that makes it JS, much like JSONP is just javascript.
application/json should only be used icw. XMLHTTPRequest objects I think.

(In reply to comment #4)

ticket collision:

It's not JSON though is it ? I mean it has "Geo =" that makes it JS, much like
JSONP is just javascript.
application/json should only be used icw. XMLHTTPRequest objects I think.

This is the right application, comment #2 and comment #3 are wrong.

text/javascript is the MIME type for executable JS. JSONP is really just executable JS that does something (call a function or set a variable) with inlined JSON data.

application/json is the MIME type for data encoded as JSON. By itself, this is valid JS, but executing it doesn't do much. This is used by XHR (i.e. normal same-domain AJAX) to grab JSON data that is then parsed (not executed!).