Compressing pages for better performance
Compressing all my pages had the sixth biggest impact when speeding up my web pages.
I had not realized the importance of having a small initial size for a webpage to speed up page load times. The 'Lighthouse' tool showed this.
I simply run my JavaScript through 'JSMin' to remove comments and unnecessary whitespace. I compiled JSMin' from source - it is a very small C program.
I will probably run my JavaScript through 'UglifyJs' when I stop making changes to my webpages. I have to go to my library to use the online 'UglifyJs' so it is a bigger job.
I shorten 'id' and 'class' names in CSS using 'sed':
tee scsstmp.html |
sed -n -e '/style type=/,/<\/style>/s@[ ]*[.#]\([a-zA-Z][a-zA-Z0-9_][a-zA-Z0-9_][a-zA-Z0-9_][a-zA-Z0-9_][a-zA-Z0-9_][a-zA-Z0-9_][a-zA-Z0-9_][a-zA-Z0-9_][a-zA-Z0-9_]*[a-zA-Z0-9_]\)[ ]*[{,:][^.#]*@:\1:@gp' | sed -e 's/::/:\n:/g' | sort -r | uniq | nl -v150 -n rz -w 3 | sed -n -e 's/^ *\([0-9][0-9]*\)\t:\([a-zA-Z][a-zA-Z0-9_]*\):/s;\2;Z\1;g/p' >scsstmp.lst
sed -f scsstmp.lst scsstmp.html
This shell script uses 'sed' to create a file of subsitutions and then runs them against the webpage.
Finally, I squash up all whitespace with a line cf shell script:
tr '\n' ' ' <jtjsm.html | tr -s '[:space:]' >jtmm.html
I also removed old unused code to further reduce the page size.
There are more tips at: bbingo.xyz/t
Comments
Post a Comment