Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable/disable GZip support. #3

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ List of features
* Several types of cache, memory and file.
* Automatically regenerates the bundle if you modify an included file.
* Proxy-friendly GZip support.
* Optional disable GZip support.
* Rewrites relative URLs in your CSS files.
* JSP, JSF, Grails integration.
* Multiple loggers support (SLF4J, Log4J, Apache Logger)
Expand Down
131 changes: 68 additions & 63 deletions jsp-demo/web/WEB-INF/granule.properties
Original file line number Diff line number Diff line change
@@ -1,63 +1,68 @@
#######################################################################
#
# Settings for compressing javascripts and css files
#
# This file should be placed in WEB-INF folder of your web application
#######################################################################

# tag.process - defines what types of resources should be processed inside of tag body
# values: all, javascript, css, ignore
# Use ignore for debug purposes
tag.process=all

# tag.method.javascript - method of compressing combined external and inline javascripts
# values: combine, jsfastmin, closure-compiler, auto
tag.method.javascript=auto

# tag.method.css - method of compressing combined external css stylesheets
# css files with different media attribute are combined into different bundles
# values: combine, cssfastmin
tag.method.css=cssfastmin

# timestampcheck - toggle checking modification time of source file of combined js or css bundles
# if the time is changed then corresponded bundle will combined and compressed again
timestampcheck=true

ignorenotfoundfiles=true

# tag.css.cleanduplicates - clean duplicate css files from bundles across tags
# usefull when web application uses many included files
tag.css.cleanduplicates=true

# tag.js.cleandupicates - clean duplicate js scripts across different tags
# (don't applies to dependent scripts from dependency calculation)
tag.js.cleandupicates=true

# the name of tag that wraps js/css scripts in the page code
# used by ant task for precompiling
tag.name=g:compress

# cache - type of cache
# values:
# memory - all combined and compressed allocated in the server memory
cache=disk

#closure-compiler - closure compiler specific instructions
#values: WHITESPACE_ONLY/SIMPLE_OPTIMIZATIONS/ADVANCED_OPTIMIZATIONS
closure-compiler.compilation_level=SIMPLE_OPTIMIZATIONS

closure-compiler.formatting.pretty_print=off

closure-compiler.formatting.print_input_delimiter=off

#closure-compiler.locale=en
#closure-compiler.output_wrapper=(function(){%output%})();
#Uncomment this wrapper For ADVANCED_OPTIMIZATIONS

closure-compiler.add-path=js/closure-samples/

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
#######################################################################
#
# Settings for compressing javascripts and css files
#
# This file should be placed in WEB-INF folder of your web application
#######################################################################

# tag.process - defines what types of resources should be processed inside of tag body
# values: all, javascript, css, ignore
# Use ignore for debug purposes
tag.process=all

# tag.method.javascript - method of compressing combined external and inline javascripts
# values: combine, jsfastmin, closure-compiler, auto
tag.method.javascript=auto

# tag.method.css - method of compressing combined external css stylesheets
# css files with different media attribute are combined into different bundles
# values: combine, cssfastmin
tag.method.css=cssfastmin

# timestampcheck - toggle checking modification time of source file of combined js or css bundles
# if the time is changed then corresponded bundle will combined and compressed again
timestampcheck=true

ignorenotfoundfiles=true

# tag.css.cleanduplicates - clean duplicate css files from bundles across tags
# usefull when web application uses many included files
tag.css.cleanduplicates=true

# tag.js.cleandupicates - clean duplicate js scripts across different tags
# (don't applies to dependent scripts from dependency calculation)
tag.js.cleandupicates=true

# the name of tag that wraps js/css scripts in the page code
# used by ant task for precompiling
tag.name=g:compress

# cache - type of cache
# values:
# memory - all combined and compressed allocated in the server memory
cache=disk

#closure-compiler - closure compiler specific instructions
#values: WHITESPACE_ONLY/SIMPLE_OPTIMIZATIONS/ADVANCED_OPTIMIZATIONS
closure-compiler.compilation_level=SIMPLE_OPTIMIZATIONS

closure-compiler.formatting.pretty_print=off

closure-compiler.formatting.print_input_delimiter=off

#closure-compiler.locale=en
#closure-compiler.output_wrapper=(function(){%output%})();
#Uncomment this wrapper For ADVANCED_OPTIMIZATIONS

closure-compiler.add-path=js/closure-samples/

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

#Enable/Disable GZip support
# Values : true, false
# Default : true
enable-gzip=true
2 changes: 1 addition & 1 deletion tag-main/src/com/granule/CompressorHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public void handle(HttpServletRequest request, HttpServletResponse response, Str

OutputStream os = response.getOutputStream();
try {
if (gzipSupported(request)) {
if (settings.getEnableGZip() && gzipSupported(request)) {
response.setHeader("Content-Encoding", "gzip");
os.write(bundle.getBundleValue());
} else
Expand Down
9 changes: 9 additions & 0 deletions tag-main/src/com/granule/CompressorSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public class CompressorSettings {
private String tagName = DEFAULT_TAG_NAME;
private String contextRoot = null;
private String basePath = null;
private boolean enableGZip = true;

public static final String NONE_VALUE = "none";
public static final String CLOSURE_COMPILER_VALUE = "closure-compiler";
Expand Down Expand Up @@ -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 ENABLE_GZIP = "enable-gzip";

public String getJsCompressMethod() {
return jsCompressMethod;
Expand Down Expand Up @@ -229,6 +231,9 @@ public void load(Utf8Properties props) throws IOException {

if (props.containsKey(CONTEXTROOT_KEY))
contextRoot = props.getProperty(CONTEXTROOT_KEY);

if (props.containsKey(ENABLE_GZIP))
enableGZip = getBoolean(props.getProperty(ENABLE_GZIP), enableGZip);
}

private void readFileListProperty(Utf8Properties props, String settingName, List<String> list) throws IOException {
Expand Down Expand Up @@ -313,6 +318,10 @@ public String getContextRoot() {
public String getBasePath() {
return basePath;
}

public boolean getEnableGZip() {
return enableGZip;
}


public static boolean getBoolean(String str, boolean defaultvalue) {
Expand Down