common: generate optimised css file for light
authorMischa POSLAWSKY <perl@shiar.org>
Sun, 11 Jun 2017 00:19:05 +0000 (02:19 +0200)
committerMischa POSLAWSKY <perl@shiar.org>
Mon, 17 Jul 2017 15:13:41 +0000 (17:13 +0200)
Strip whitespace and comments to reduce download size by 6kB (35%).
Silences site analysers such as Google PageSpeed about unminified CSS:

> Compacting CSS code can save many bytes of data and speed up download and
> parse times.
> Minifying http://sheet.shiar.nl/base.css could save 2KiB (41% reduction)
> after compression.

Tried a couple of existing tools [from Debian] but they mostly failed to
parse more complex rules, or tried to make unwanted "improvements".
Rather write some simple regexes to specifically and transparently replace
whitespace and comments.

.gitignore
Makefile
light.css [deleted symlink]

index bec2de1f24a3ddb6ccc14b775c5c0b95107371fe..5c53b312bee52468fc3ec73056124071c8dfbcbd 100644 (file)
@@ -3,6 +3,7 @@
 
 # derived contents
 /sitemap.xml
 
 # derived contents
 /sitemap.xml
+/light.css
 
 # site owner tag for google webmaster tools
 /google????????????????.html
 
 # site owner tag for google webmaster tools
 /google????????????????.html
index a21f87bd95fbf125fc7d4312c1b0240f577845c8..349e34f9399f2d8d2584c13c7caf4388653cdcfb 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1,11 +1,11 @@
-all: sitemap.xml data/digraphs.inc.pl data/unicode-cover.inc.pl data/countries.inc.pl data/browser data/termcol-xcolor.inc.pl data/digraphs-xorg.inc.pl
+all: sitemap.xml light.css data/digraphs.inc.pl data/unicode-cover.inc.pl data/countries.inc.pl data/browser data/termcol-xcolor.inc.pl data/digraphs-xorg.inc.pl
 more: all
 
 download: data/DerivedAge.txt data/rfc1345.txt data/xorg-compose data/countryInfo.txt data/browser/caniuse data/browser/usage-wm.tsv data/xcolors data/unicode-sampler
 .PHONY: download
 
 # atomically create file by command
 more: all
 
 download: data/DerivedAge.txt data/rfc1345.txt data/xorg-compose data/countryInfo.txt data/browser/caniuse data/browser/usage-wm.tsv data/xcolors data/unicode-sampler
 .PHONY: download
 
 # atomically create file by command
-cmdsave = @echo $1 $2 \>$@; mispipe '$1 $2' 'ifne sponge $@'
+cmdsave = @echo '$1' $2 \>$@; mispipe '$1 $2' 'ifne sponge $@'
 # download git checkout
 gitsave = @if cd $@ 2>/dev/null; \
        then echo git pull $@; git pull -q --ff-only || true; \
 # download git checkout
 gitsave = @if cd $@ 2>/dev/null; \
        then echo git pull $@; git pull -q --ff-only || true; \
@@ -14,6 +14,9 @@ gitsave = @if cd $@ 2>/dev/null; \
 sitemap.xml: tools/mksitemap
        $(call cmdsave,$<)
 
 sitemap.xml: tools/mksitemap
        $(call cmdsave,$<)
 
+light.css: base.css
+       $(call cmdsave,perl -pe '\''s!\s*/\*.*\*/\Z!!; s/^\s*//; s/\h+/ /g; s/:\K\h+//;'\'',$<)
+
 data/DerivedAge.txt:
        tools/wget-ifmodified http://www.unicode.org/Public/UNIDATA/$(@F) $@
 
 data/DerivedAge.txt:
        tools/wget-ifmodified http://www.unicode.org/Public/UNIDATA/$(@F) $@
 
diff --git a/light.css b/light.css
deleted file mode 120000 (symlink)
index e734484..0000000
--- a/light.css
+++ /dev/null
@@ -1 +0,0 @@
-base.css
\ No newline at end of file