diff options
author | Mikael Grankvist <mgrankvi@vaadin.com> | 2014-06-19 09:31:19 +0300 |
---|---|---|
committer | Artur Signell <artur@vaadin.com> | 2014-06-26 12:04:25 +0000 |
commit | a685cc8a595509c707aa692d32b1daa2fea4ca57 (patch) | |
tree | d6151a0c838df8386bd360e66ddc1996615515a8 /client | |
parent | 1b73b00b2875c5eafa3c641b77f5d9efc2f7d929 (diff) | |
download | vaadin-framework-a685cc8a595509c707aa692d32b1daa2fea4ca57.tar.gz vaadin-framework-a685cc8a595509c707aa692d32b1daa2fea4ca57.zip |
IE11 now uses synchronous loading of script instead of async with preloading. (#13956)
Change-Id: Ia61d672a55f69326b37420305f0108f2d7443b70
Diffstat (limited to 'client')
-rw-r--r-- | client/src/com/vaadin/client/ApplicationConnection.java | 16 | ||||
-rw-r--r-- | client/src/com/vaadin/client/ResourceLoader.java | 39 |
2 files changed, 50 insertions, 5 deletions
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) { @@ -252,6 +275,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 * preloaded, it will be present in the browser's cache (provided the HTTP @@ -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"); |