Add Makefile target for precompressing *.css and *.js and httpd.conf section for serving them compressed.
authorVille Skyttä <ville.skytta@iki.fi>
Sun, 12 Dec 2010 20:27:00 +0200
changeset 3180 13be4ea042d6
parent 3179 10daea062d0e
child 3181 d82323fdd090
Add Makefile target for precompressing *.css and *.js and httpd.conf section for serving them compressed.
.hgignore
Makefile
httpd/conf/httpd.conf
--- a/.hgignore	Sun Dec 12 14:33:33 2010 +0200
+++ b/.hgignore	Sun Dec 12 20:27:00 2010 +0200
@@ -2,7 +2,7 @@
 
 .project
 *.pyc
-*.tar.gz
+*.gz
 httpd/cgi-bin/*.bak
 misc/*.bak
 misc/bundle/*.bak
--- a/Makefile	Sun Dec 12 14:33:33 2010 +0200
+++ b/Makefile	Sun Dec 12 20:27:00 2010 +0200
@@ -1,15 +1,20 @@
 VERSION = $(shell perl -ne '/^\$$VERSION\b.*?([\d.]+)/ && print $$1' httpd/cgi-bin/check)
 
+CSS_FILES = $(wildcard htdocs/*.css htdocs/style/*.css)
+JS_FILES = $(wildcard htdocs/scripts/*.js)
 PERL_FILES = httpd/cgi-bin/check httpd/cgi-bin/sendfeedback.pl \
 	misc/soc2xml.pl misc/spmpp.pl misc/docs_errors.pl \
 	misc/bundle/Makefile.PL misc/bundle/lib/Bundle/W3C/Validator.pm
+GZIP_FILES = $(addsuffix .gz,$(CSS_FILES) $(JS_FILES))
 
 PERLTIDY = perltidy --profile=misc/perltidyrc --backup-and-modify-in-place
 PERLCRITIC = perlcritic --profile misc/perlcriticrc
 
+GZIP = gzip -9n
+
 VALIDATOR_URI = http://localhost/w3c-validator/check
 
-all: htdocs/docs/errors.html htdocs/sgml-lib/catalog.xml
+all: htdocs/docs/errors.html htdocs/sgml-lib/catalog.xml $(GZIP_FILES)
 
 htdocs/docs/errors.html: misc/docs_errors.pl share/templates/en_US/error_messages.cfg share/templates/en_US/docs_errors.tmpl htdocs/config/validator.conf
 	env W3C_VALIDATOR_HOME=. W3C_VALIDATOR_CFG=htdocs/config/validator.conf misc/docs_errors.pl > $@
@@ -17,6 +22,9 @@
 htdocs/sgml-lib/catalog.xml: misc/soc2xml.pl htdocs/sgml-lib/xml.soc
 	misc/soc2xml.pl < htdocs/sgml-lib/xml.soc > $@
 
+.css.css.gz .js.js.gz:
+	$(GZIP) -c $< > $@ && touch -r $< $@
+
 test:
 	misc/testsuite/harness.py --validator_uri=$(VALIDATOR_URI) run
 
@@ -29,6 +37,9 @@
 		$(PERLTIDY) $$file ; \
 	done
 
+clean:
+	rm -f $(GZIP_FILES)
+
 dist: all
 	@for file in htdocs/footer.html htdocs/whatsnew.html \
 		httpd/cgi-bin/check share/templates/*/footer.tmpl ; do \
@@ -37,3 +48,5 @@
 		exit 1 ; } ; \
 	done
 	misc/mkrelease.sh $(VERSION)
+
+.SUFFIXES: .css .css.gz .js .js.gz
--- a/httpd/conf/httpd.conf	Sun Dec 12 14:33:33 2010 +0200
+++ b/httpd/conf/httpd.conf	Sun Dec 12 20:27:00 2010 +0200
@@ -46,7 +46,14 @@
   AllowOverride         None
   AddHandler            server-parsed .html
   AddCharset            utf-8         .html
-            
+  AddEncoding           x-gzip        .gz
+  <Files *.js.gz>
+    ForceType           application/javascript
+  </Files>
+  <Files *.css.gz>
+    ForceType           text/css
+  </Files>
+
   <IfModule mod_rewrite.c>
   Options +SymLinksIfOwnerMatch
   RewriteEngine On