diff --git a/optim-classes.sh b/optim-classes.sh index 29a11c8..34bac95 100755 --- a/optim-classes.sh +++ b/optim-classes.sh @@ -36,7 +36,7 @@ i=0; typeset -A assoc for c in $classes; do sn=$(shortName $i) - print "$c -> $sn" + print -- "$c -> $sn" assoc[$c]=$sn ((i++)) done @@ -48,12 +48,21 @@ for long in $classes; do cssreplacer=$cssreplacer's#\.'${long}'#.'${assoc[$long]}'#g;' done +sizeof() { + stat --format="%s" "$*" +} for fic in $webdir/**/*.{html,xml}(N); do - print -- $fic + before=$(sizeof $fic) + print -n -- "$fic ($before" perl -pi -e $htmlreplacer $fic + after=$(sizeof $fic) + print -- " => $after [$(( ((before - after) * 100) / before ))])" done for fic in $webdir/**/*.css(N); do - echo $fic + before=$(sizeof $fic) + print -n -- "$fic ($before" perl -pi -e $cssreplacer $fic + after=$(sizeof $fic) + print -- " => $after [$(( ((before - after) * 100) / before ))])" done diff --git a/src/posts/0009-optim-nojs-website/index.org b/src/posts/0009-optim-nojs-website/index.org index 59e5e7c..a1e1eb3 100644 --- a/src/posts/0009-optim-nojs-website/index.org +++ b/src/posts/0009-optim-nojs-website/index.org @@ -22,14 +22,49 @@ is always the risk the JS code generate class names to manipulate the DOM. So here is a small script I wanted to write from a long time that do the following: 1. retrieve all class names in the HTML and in the CSS -2. create an associative from those long names to shorter names +2. create a map from those long names to shorter names 3. replace the class names in the HTML and CSS files. -Here is my quick and dirty script doing that: +So if you have multiple HTML files with: + +#+begin_src html +