From a685cc8a595509c707aa692d32b1daa2fea4ca57 Mon Sep 17 00:00:00 2001 From: Mikael Grankvist Date: Thu, 19 Jun 2014 09:31:19 +0300 Subject: IE11 now uses synchronous loading of script instead of async with preloading. (#13956) Change-Id: Ia61d672a55f69326b37420305f0108f2d7443b70 --- .../com/vaadin/client/ApplicationConnection.java | 16 ++++++--- client/src/com/vaadin/client/ResourceLoader.java | 39 ++++++++++++++++++++++ 2 files changed, 50 insertions(+), 5 deletions(-) (limited to 'client') diff --git a/client/src/com/vaadin/client/ApplicationConnection.java b/client/src/com/vaadin/client/ApplicationConnection.java index 50f22edf81..c39beffd87 100644 --- a/client/src/com/vaadin/client/ApplicationConnection.java +++ b/client/src/com/vaadin/client/ApplicationConnection.java @@ -66,7 +66,6 @@ import com.google.gwt.user.client.Window.ClosingHandler; import com.google.gwt.user.client.ui.HasWidgets; import com.google.gwt.user.client.ui.Widget; import com.vaadin.client.ApplicationConfiguration.ErrorMessage; -import com.vaadin.client.ApplicationConnection.ApplicationStoppedEvent; import com.vaadin.client.ResourceLoader.ResourceLoadEvent; import com.vaadin.client.ResourceLoader.ResourceLoadListener; import com.vaadin.client.communication.HasJavaScriptConnectorHelper; @@ -2499,10 +2498,17 @@ public class ApplicationConnection implements HasHandlers { ApplicationConfiguration.startDependencyLoading(); loader.loadScript(url, resourceLoadListener); - // Preload all remaining - for (int i = 0; i < dependencies.length(); i++) { - String preloadUrl = translateVaadinUri(dependencies.get(i)); - loader.preloadResource(preloadUrl, null); + if (ResourceLoader.supportsInOrderScriptExecution()) { + for (int i = 0; i < dependencies.length(); i++) { + String preloadUrl = translateVaadinUri(dependencies.get(i)); + loader.loadScript(preloadUrl, null); + } + } else { + // Preload all remaining + for (int i = 0; i < dependencies.length(); i++) { + String preloadUrl = translateVaadinUri(dependencies.get(i)); + loader.preloadResource(preloadUrl, null); + } } } diff --git a/client/src/com/vaadin/client/ResourceLoader.java b/client/src/com/vaadin/client/ResourceLoader.java index 59ebd797d1..e88def1a72 100644 --- a/client/src/com/vaadin/client/ResourceLoader.java +++ b/client/src/com/vaadin/client/ResourceLoader.java @@ -204,6 +204,26 @@ public class ResourceLoader { */ public void loadScript(final String scriptUrl, final ResourceLoadListener resourceLoadListener) { + loadScript(scriptUrl, resourceLoadListener, + !supportsInOrderScriptExecution()); + } + + /** + * Load a script and notify a listener when the script is loaded. Calling + * this method when the script is currently loading or already loaded + * doesn't cause the script to be loaded again, but the listener will still + * be notified when appropriate. + * + * + * @param scriptUrl + * url of script to load + * @param resourceLoadListener + * listener to notify when script is loaded + * @param async + * What mode the script.async attribute should be set to + */ + public void loadScript(final String scriptUrl, + final ResourceLoadListener resourceLoadListener, boolean async) { final String url = Util.getAbsoluteUrl(scriptUrl); ResourceLoadEvent event = new ResourceLoadEvent(this, url, false); if (loadedResources.contains(url)) { @@ -236,6 +256,9 @@ public class ResourceLoader { ScriptElement scriptTag = Document.get().createScriptElement(); scriptTag.setSrc(url); scriptTag.setType("text/javascript"); + + scriptTag.setPropertyBoolean("async", async); + addOnloadHandler(scriptTag, new ResourceLoadListener() { @Override public void onLoad(ResourceLoadEvent event) { @@ -251,6 +274,17 @@ public class ResourceLoader { } } + /** + * The current browser supports script.async='false' for maintaining + * execution order for dynamically-added scripts. + * + * @return Browser supports script.async='false' + */ + public static boolean supportsInOrderScriptExecution() { + return BrowserInfo.get().isIE() + && BrowserInfo.get().getBrowserMajorVersion() >= 11; + } + /** * Download a resource and notify a listener when the resource is loaded * without attempting to interpret the resource. When a resource has been @@ -316,6 +350,11 @@ public class ResourceLoader { * XHR not tested - should work, probably causes other issues -*/ if (BrowserInfo.get().isIE()) { + // If ie11+ for some reason gets a preload request + if (BrowserInfo.get().getBrowserMajorVersion() >= 11) { + throw new RuntimeException( + "Browser doesn't support preloading with text/cache"); + } ScriptElement element = Document.get().createScriptElement(); element.setSrc(url); element.setType("text/cache"); -- cgit v1.2.3