shindig-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jo...@apache.org
Subject svn commit: r1145376 - /shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/js/JsLoadProcessor.java
Date Mon, 11 Jul 2011 21:59:21 GMT
Author: johnh
Date: Mon Jul 11 21:59:20 2011
New Revision: 1145376

URL: http://svn.apache.org/viewvc?rev=1145376&view=rev
Log:
Optional ability for &jsload=1 to be async by default.


Modified:
    shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/js/JsLoadProcessor.java

Modified: shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/js/JsLoadProcessor.java
URL: http://svn.apache.org/viewvc/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/js/JsLoadProcessor.java?rev=1145376&r1=1145375&r2=1145376&view=diff
==============================================================================
--- shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/js/JsLoadProcessor.java
(original)
+++ shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/js/JsLoadProcessor.java
Mon Jul 11 21:59:20 2011
@@ -43,10 +43,18 @@ public class JsLoadProcessor implements 
   public static final String JSLOAD_JS_TPL = "(function() {" +
       "document.write('<scr' + 'ipt type=\"text/javascript\" src=\"%s\"></scr' +
'ipt>');" +
       "})();"; // Concatenated to avoid some browsers do dynamic script injection.
+  
+  @VisibleForTesting
+  public static final String ASYNC_JSLOAD_JS_TPL = "(function() {" +
+      "var s=document.createElement('script');" +
+      "s.src=\"%s\";" +
+      "document.getElementsByTagName('head')[0].appendChild(s);" +
+      "})();";
 
   private final JsUriManager jsUriManager;
   private final int jsloadTtlSecs;
   private final boolean requireOnload;
+  private String template;
 
   @Inject
   public JsLoadProcessor(
@@ -56,6 +64,14 @@ public class JsLoadProcessor implements 
     this.jsUriManager = jsUriManager;
     this.jsloadTtlSecs = jsloadTtlSecs;
     this.requireOnload = requireOnload;
+    this.template = JSLOAD_JS_TPL;
+  }
+  
+  @Inject(optional = true)
+  public void setUseAsync(@Named("shindig.jsload.async-mode") Boolean jsloadAsync) {
+    if (jsloadAsync) {
+      template = ASYNC_JSLOAD_JS_TPL;
+    }
   }
 
   public boolean process(JsRequest request, JsResponseBuilder builder)
@@ -97,7 +113,7 @@ public class JsLoadProcessor implements 
 
   protected String createJsloadScript(Uri uri) {
     String uriString = uri.toString();
-    return String.format(JSLOAD_JS_TPL, uriString);
+    return String.format(template, uriString);
   }
 
   private int getCacheTtlSecs(JsUri jsUri) {



Mime
View raw message