You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tapestry.apache.org by jk...@apache.org on 2006/12/03 02:29:29 UTC

svn commit: r481686 - /tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/asset/AssetService.java

Author: jkuhnert
Date: Sat Dec  2 17:29:27 2006
New Revision: 481686

URL: http://svn.apache.org/viewvc?view=rev&rev=481686
Log:
Oh boy. I must've been bored today. :) Sure is like 6-7x faster with this one little change though. (literally)

Modified:
    tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/asset/AssetService.java

Modified: tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/asset/AssetService.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/asset/AssetService.java?view=diff&rev=481686&r1=481685&r2=481686
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/asset/AssetService.java (original)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/asset/AssetService.java Sat Dec  2 17:29:27 2006
@@ -14,6 +14,7 @@
 
 package org.apache.tapestry.asset;
 
+import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
@@ -26,6 +27,7 @@
 import java.util.Locale;
 import java.util.Map;
 import java.util.TreeMap;
+import java.util.zip.GZIPOutputStream;
 
 import javax.servlet.http.HttpServletResponse;
 
@@ -367,7 +369,7 @@
 
             String contentType = getMimeType(resourcePath);
             int contentLength = resourceConnection.getContentLength();
-
+            
             if (contentLength > 0)
                 _response.setContentLength(contentLength);
             
@@ -397,6 +399,29 @@
             input = resourceConnection.getInputStream();
             
             byte[] data = IOUtils.toByteArray(input);
+            
+            // compress javascript responses when possible
+            
+            if (contentType.indexOf("javascript") > -1
+                    || contentType.indexOf("css") > -1 
+                    || contentType.indexOf("html") > -1
+                    || contentType.indexOf("text") > -1) {
+                String encoding = _request.getHeader("Accept-Encoding");
+                if (encoding != null && encoding.indexOf("gzip") > -1) {
+                    
+                    ByteArrayOutputStream bo = 
+                        new ByteArrayOutputStream();
+                    GZIPOutputStream gzip = 
+                        new GZIPOutputStream(bo);
+                    
+                    gzip.write(data);
+                    gzip.close();
+                    
+                    data = bo.toByteArray();
+                    
+                    _response.setHeader("Content-Encoding", "gzip");
+                }
+            }
             
             // force image(or other) caching when detected, esp helps with ie related things
             // see http://mir.aculo.us/2005/08/28/internet-explorer-and-ajax-image-caching-woes