Ticket #2933 (closed bug: fixed)

Opened 3 years ago

Last modified 2 years ago

OpenLayers runs HTML5-incompatible script loading code if the UA string doesn't contain "Safari" or "MSIE"

Reported by: hsivonen Owned by:
Priority: critical Milestone: 2.11 Release
Component: general Version: 2.10
Keywords: Cc: nakor
State: Commit

Description

OpenLayers has this bit:

var agent = navigator.userAgent;

var docWrite = (agent.match("MSIE") agent.match("Safari")); if(docWrite) {

var allScriptTags = new Array(jsfiles.length);

} var host = OpenLayers._getScriptLocation() + "lib/"; for (var i=0, len=jsfiles.length; i<len; i++) {

if (docWrite) {

allScriptTags[i] = "<script src='" + host + jsfiles[i] +

"'></script>";

} else {

var s = document.createElement("script"); s.src = host + jsfiles[i]; var h = document.getElementsByTagName("head").length ?

document.getElementsByTagName("head")[0] : document.body;

h.appendChild(s);

}

} if (docWrite) {

document.write(allScriptTags.join(""));

}

When docWrite is false, the code that is run doesn't work in browsers that implement script loading and execution according to HTML5 ( http://www.w3.org/TR/html5/scripting-1.html#running-a-script). This includes Firefox 4 beta 7.

To make OpenLayers work in browsers that implement script loading and execution according to HTML5 but that don't contain "MSIE" or "Safari" in the UA string, please run the document.write()-based code path in all browsers.

For more information, please see  http://hsivonen.iki.fi/script-execution/

Attachments

patch-2933-A0.diff Download (1.4 KB) - added by erilem 3 years ago.

Change History

  Changed 3 years ago by nakor

  • cc nakor added

  Changed 3 years ago by erilem

Thanks a lot for reporting about this. I'll have a look.

  Changed 3 years ago by erilem

So my understanding is that, to be compatible with every browser, we need to use "parser-inserted scripts" (with document.write) in every browser, even though this will increase loading time in FF (and webkits?) because scripts won't load in parallel.

Changed 3 years ago by erilem

  Changed 3 years ago by erilem

  • state set to Review

I tested patch-2933-A0.diff Download in FF3, FF4, Chrome7, IE7, and Safari3. Please review.

follow-up: ↓ 6   Changed 3 years ago by hsivonen

In WebKit, you are already using document.write and script aren't loading in parallel, so there'd be no load time increase compared to the status quo.

In Firefox trunk right now, using document.write would increase load time compared to your current setup in Firefox 3.6. However, document.written scripts will load in parallel once  https://bugzilla.mozilla.org/show_bug.cgi?id=543062 is fixed.

Contrary to what I wrote in  http://hsivonen.iki.fi/script-execution/ , the current plan (but not promise) is to make document.written scripts load in parallel in Firefox 4. (This retargeting to Firefox 4 is a new development after I filed this OpenLayers bug. The motivation of the retargeting to Firefox 4 is to make it possible for OpenLayers to move to cross-browser-compatible code without losing parallel loads in Firefox.)

Your patch looks good to me.

in reply to: ↑ 5   Changed 3 years ago by erilem

Replying to hsivonen:

In WebKit, you are already using document.write and script aren't loading in parallel, so there'd be no load time increase compared to the status quo. In Firefox trunk right now, using document.write would increase load time compared to your current setup in Firefox 3.6. However, document.written scripts will load in parallel once  https://bugzilla.mozilla.org/show_bug.cgi?id=543062 is fixed. Contrary to what I wrote in  http://hsivonen.iki.fi/script-execution/ , the current plan (but not promise) is to make document.written scripts load in parallel in Firefox 4. (This retargeting to Firefox 4 is a new development after I filed this OpenLayers bug. The motivation of the retargeting to Firefox 4 is to make it possible for OpenLayers to move to cross-browser-compatible code without losing parallel loads in Firefox.) Your patch looks good to me.

Thanks a lot for your support, and the thorough explanations.

  Changed 2 years ago by hsivonen

Did this bug make it onto a reviewer's todo list?

  Changed 2 years ago by aabt

Works for me. I'd be happy to see this patch reviewed & commited… :)

  Changed 2 years ago by pgiraud

  • state changed from Review to Commit

This patch lookks good to me too. I think we can commit it now. Tested on FF3.6, FF4, Chrome 9, and IE8.

  Changed 2 years ago by erilem

  • status changed from new to closed
  • resolution set to fixed

Fixed with [11036] (and [11037]).

  Changed 2 years ago by hsivonen

When will OpenLayers 2.11 be released? Firefox 4 has moved to release candidate builds, so it would be really nice to have a Firefox 4-compatible version of OpenLayers available.

Note: See TracTickets for help on using tickets.