]> source.dussan.org Git - vaadin-framework.git/commitdiff
Appending query param with vaadin version to js files (#12210)
authorFabian Lange <lange.fabian@gmail.com>
Wed, 23 Jul 2014 20:40:35 +0000 (22:40 +0200)
committerVaadin Code Review <review@vaadin.com>
Sun, 11 Jan 2015 15:09:51 +0000 (15:09 +0000)
while #7868 is supposed to solve the overall issue, this solves a big
part of the upgrade + cached files issues quickly.
When I use vaadin themes, I have control over how they are included, so
I can add a vaadin version number to it. For the default JS I cannot.

Change-Id: Ica1cddee417946aa32116eb09882a3dc6c2924a6

WebContent/VAADIN/vaadinBootstrap.js
client/src/com/vaadin/client/communication/AtmospherePushConnection.java
client/src/com/vaadin/client/ui/ui/UIConnector.java
server/src/com/vaadin/server/BootstrapHandler.java

index ced077138fc435a54f1c18feace18d33829c3f76..53b213e11065f8810f990210a3e53a9a0b34a395 100644 (file)
        log = console.log;
     }
        
-       var loadTheme = function(url) {
+       var loadTheme = function(url, version) {
                if(!themesLoaded[url]) {
-                       log("loadTheme", url);
+                       log("loadTheme", url, version);
+                       
+                       var href = url + '/styles.css';
+                       if (version) {
+                               href += '?v=' + version;
+                       }
+                       
                        var stylesheet = document.createElement('link');
                        stylesheet.setAttribute('rel', 'stylesheet');
                        stylesheet.setAttribute('type', 'text/css');
-                       stylesheet.setAttribute('href', url + "/styles.css");
+                       stylesheet.setAttribute('href', href);
                        document.getElementsByTagName('head')[0].appendChild(stylesheet);
                        themesLoaded[url] = true;
                }               
                        var bootstrapApp = function(mayDefer) {
                                var vaadinDir = getConfig('vaadinDir');
                                
+                               var versionInfo = getConfig('versionInfo');
+                               
                                var themeUri = vaadinDir + 'themes/' + getConfig('theme');
-                               loadTheme(themeUri);
+                               loadTheme(themeUri, versionInfo && versionInfo['vaadinVersion']);
                                
                                var widgetset = getConfig('widgetset');
                                var widgetsetUrl = getConfig('widgetsetUrl');
index a2c4dd832349e30a614c28aad057f6d884ab6ace..d10449ccaa71a47f570ae97bd3345d9697f39488 100644 (file)
@@ -31,6 +31,7 @@ import com.vaadin.client.ResourceLoader.ResourceLoadEvent;
 import com.vaadin.client.ResourceLoader.ResourceLoadListener;
 import com.vaadin.client.VConsole;
 import com.vaadin.shared.ApplicationConstants;
+import com.vaadin.shared.Version;
 import com.vaadin.shared.communication.PushConstants;
 import com.vaadin.shared.ui.ui.UIConstants;
 import com.vaadin.shared.ui.ui.UIState.PushConfigurationState;
@@ -514,16 +515,10 @@ public class AtmospherePushConnection implements PushConnection {
     }-*/;
 
     private void runWhenAtmosphereLoaded(final Command command) {
-
         if (isAtmosphereLoaded()) {
             command.execute();
         } else {
-            final String pushJs;
-            if (ApplicationConfiguration.isProductionMode()) {
-                pushJs = ApplicationConstants.VAADIN_PUSH_JS;
-            } else {
-                pushJs = ApplicationConstants.VAADIN_PUSH_DEBUG_JS;
-            }
+            final String pushJs = getVersionedPushJs();
 
             VConsole.log("Loading " + pushJs);
             ResourceLoader.get().loadScript(
@@ -553,6 +548,18 @@ public class AtmospherePushConnection implements PushConnection {
         }
     }
 
+    private String getVersionedPushJs() {
+        String pushJs;
+        if (ApplicationConfiguration.isProductionMode()) {
+            pushJs = ApplicationConstants.VAADIN_PUSH_JS;
+        } else {
+            pushJs = ApplicationConstants.VAADIN_PUSH_DEBUG_JS;
+        }
+        // Parameter appended to bypass caches after version upgrade.
+        pushJs += "?v=" + Version.getFullVersion();
+        return pushJs;
+    }
+
     /*
      * (non-Javadoc)
      * 
index d6f14bf15878f4c9f5ab3d5c5ba4e0430c592d6f..9e1da113bf2b6f88c95f27bd8f4f4aee5f0bc2ff 100644 (file)
@@ -76,6 +76,7 @@ import com.vaadin.client.ui.window.WindowConnector;
 import com.vaadin.server.Page.Styles;
 import com.vaadin.shared.ApplicationConstants;
 import com.vaadin.shared.MouseEventDetails;
+import com.vaadin.shared.Version;
 import com.vaadin.shared.communication.MethodInvocation;
 import com.vaadin.shared.ui.ComponentStateUtil;
 import com.vaadin.shared.ui.Connect;
@@ -1014,9 +1015,13 @@ public class UIConnector extends AbstractSingleComponentContainerConnector
      * @return The URL the theme can be loaded from
      */
     private String getThemeUrl(String theme) {
-        return getConnection().translateVaadinUri(
+        String themeUrl = getConnection().translateVaadinUri(
                 ApplicationConstants.VAADIN_PROTOCOL_PREFIX + "themes/" + theme
                         + "/styles" + ".css");
+        // Parameter appended to bypass caches after version upgrade.
+        themeUrl += "?v=" + Version.getFullVersion();
+        return themeUrl;
+
     }
 
     /**
index 30e43f48a88aacf52e438af6c9dcb37829186263..c45e2b70e019e364ddd53b3372f702fcb67d038e 100644 (file)
@@ -414,6 +414,9 @@ public abstract class BootstrapHandler extends SynchronizedRequestHandler {
         String vaadinLocation = vaadinService.getStaticFileLocation(request)
                 + "/VAADIN/";
 
+        // Parameter appended to JS to bypass caches after version upgrade.
+        String versionQueryParam = "?v=" + Version.getFullVersion();
+
         if (context.getPushMode().isEnabled()) {
             // Load client-side dependencies for push support
             String pushJS = vaadinLocation;
@@ -424,12 +427,14 @@ public abstract class BootstrapHandler extends SynchronizedRequestHandler {
                 pushJS += ApplicationConstants.VAADIN_PUSH_DEBUG_JS;
             }
 
+            pushJS += versionQueryParam;
+
             fragmentNodes.add(new Element(Tag.valueOf("script"), "").attr(
                     "type", "text/javascript").attr("src", pushJS));
         }
 
         String bootstrapLocation = vaadinLocation
-                + ApplicationConstants.VAADIN_BOOTSTRAP_JS;
+                + ApplicationConstants.VAADIN_BOOTSTRAP_JS + versionQueryParam;
         fragmentNodes.add(new Element(Tag.valueOf("script"), "").attr("type",
                 "text/javascript").attr("src", bootstrapLocation));
         Element mainScriptTag = new Element(Tag.valueOf("script"), "").attr(
@@ -613,7 +618,7 @@ public abstract class BootstrapHandler extends SynchronizedRequestHandler {
     }
 
     /**
-     * Don not override.
+     * Do not override.
      * 
      * @param context
      * @return