diff --git a/grails-demo/web-app/WEB-INF/granule.properties b/grails-demo/web-app/WEB-INF/granule.properties index 164ff79..152fb12 100644 --- a/grails-demo/web-app/WEB-INF/granule.properties +++ b/grails-demo/web-app/WEB-INF/granule.properties @@ -54,4 +54,8 @@ closure-compiler.add-path=js/closure-samples/ keepfirstcommentpath=js/dojo/*,js/superslider/slider.js,js/jquery*.js +#If set to true, JS and CSS files are returned after gzip compression +#By default, this is set to true. +#If server is already configured to gzip response for some reasons, then set this flag to false to avoid double gzip compression. +gzip.output=true diff --git a/jsp-demo/web/WEB-INF/granule.properties b/jsp-demo/web/WEB-INF/granule.properties index dabcf54..bd7953e 100644 --- a/jsp-demo/web/WEB-INF/granule.properties +++ b/jsp-demo/web/WEB-INF/granule.properties @@ -60,4 +60,9 @@ keepfirstcommentpath=js/dojo/*,js/superslider/slider.js,js/jquery*.js # contextroot - the constant context root of web-applications. # It need to be setup right for ant cache precompiling if there are hard-coded URLs in the pages -contextroot=web \ No newline at end of file +contextroot=web + +#If set to true, JS and CSS files are returned after gzip compression +#By default, this is set to true. +#If server is already configured to gzip response for some reasons, then set this flag to false to avoid double gzip compression. +gzip.output=true \ No newline at end of file diff --git a/tag-main/src/com/granule/CompressorHandler.java b/tag-main/src/com/granule/CompressorHandler.java index 23c702e..fad0af2 100644 --- a/tag-main/src/com/granule/CompressorHandler.java +++ b/tag-main/src/com/granule/CompressorHandler.java @@ -53,7 +53,7 @@ public void handle(HttpServletRequest request, HttpServletResponse response, Str OutputStream os = response.getOutputStream(); try { - if (gzipSupported(request)) { + if (settings.isGzipOutput() && gzipSupported(request)) { response.setHeader("Content-Encoding", "gzip"); os.write(bundle.getBundleValue()); } else diff --git a/tag-main/src/com/granule/CompressorSettings.java b/tag-main/src/com/granule/CompressorSettings.java index c8c4436..2d7b19f 100644 --- a/tag-main/src/com/granule/CompressorSettings.java +++ b/tag-main/src/com/granule/CompressorSettings.java @@ -50,6 +50,7 @@ public class CompressorSettings { private String tagName = DEFAULT_TAG_NAME; private String contextRoot = null; private String basePath = null; + private boolean gzipOutput = true; public static final String NONE_VALUE = "none"; public static final String CLOSURE_COMPILER_VALUE = "closure-compiler"; @@ -88,6 +89,7 @@ public class CompressorSettings { public static final String DEFAULT_TAG_NAME = "g:compress"; public static final String CONTEXTROOT_KEY = "contextroot"; public static final String BASEPATH_KEY = "basepath"; + public static final String GZIP_OUTPUT_KEY = "gzip.output"; public String getJsCompressMethod() { return jsCompressMethod; @@ -131,6 +133,20 @@ public String getOutputWrapperMarker() { public String getTagName() { return tagName; + } + + /** + * @return Returns the gzipOutput. + */ + public boolean isGzipOutput() { + return gzipOutput; + } + + /** + * @param gzipOutput The gzipOutput to set. + */ + public void setGzipOutput(boolean gzipOutput) { + this.gzipOutput = gzipOutput; } public void load(Utf8Properties props) throws IOException { @@ -229,6 +245,10 @@ public void load(Utf8Properties props) throws IOException { if (props.containsKey(CONTEXTROOT_KEY)) contextRoot = props.getProperty(CONTEXTROOT_KEY); + + if(props.containsKey(GZIP_OUTPUT_KEY)){ + gzipOutput = getBoolean(props.getProperty(GZIP_OUTPUT_KEY), gzipOutput); + } } private void readFileListProperty(Utf8Properties props, String settingName, List list) throws IOException { diff --git a/tag-main/src/com/granule/utils/CSSHandler.java b/tag-main/src/com/granule/utils/CSSHandler.java index 57d4a62..203c15e 100644 --- a/tag-main/src/com/granule/utils/CSSHandler.java +++ b/tag-main/src/com/granule/utils/CSSHandler.java @@ -39,7 +39,7 @@ public final class CSSHandler { private static final String stringLiteralRegex = "(\"(?:\\.|[^\\\"])*\"|'(?:\\.|[^\\'])*')"; private static final String urlRegex = String.format( - "(?:url\\(\\s*(%s|[^)]*)\\s*\\))", stringLiteralRegex); + "(?:url\\(\\s*(?!\\s*\\'\\/)(?!\\s*\\\"\\/)(?!\\s*\\/)(%s|[^)]*)\\s*\\))", stringLiteralRegex); private static final String importRegex = String.format( "(?:@import\\s+(%s|%s))", urlRegex, stringLiteralRegex);