sitecompiler is a Makefile that uses a suite of several minifiers, general purpose compressors, and image & video optimisers and encoders to compress websites. It supports web content such as .html .css and .js, image file types such as .png .jpg .gif .svg and .webp, general purpose brotli and zopfli file compressors for producing .gz and .br files, as well as support for encoding images & videos into the AV1 codec, producing .avif and .webm files respectively.
- I'll answer a question you probably have first off - sitecompiler does not alter any existing files, it will only create new compressed versions of those files so that development work can continue to be done on the original files, and then compressed for deployment.
- The only case where files may be unintentially overwritten is if you have image files with with different extensions but the same name in a directory, but the contents of those files are not the same. E.g. if you have a directory with image.jpg, and image.webp, sitecompiler will assume those are meant to be the same image, and if image.jpg is newer than image.webp, image.webp will be overwritten with a compressed version of image.jpg.
- Run
make dependto update or install any dependencies that might be needed. makewill run the default recipe which iswebcontentwhich processes.html.cssand.jsfiles, once sitecompiler is done you will have a*.gzand*.brversion of all the web content files in your website that should be significantly smaller than they were originally.- The first time you run site compiler it will ask for the directory of your website, enter
.for the current directory. - As with all
makethings, runmake -jNwithNbeing the number of jobs to run in parallel for more fastness.
- The first time you run site compiler it will ask for the directory of your website, enter
- When you update any the files in your website, run
makeagain and the new files will be processed.
make webcontentprocesses.html.cssand.jsfiles, to do these file types individually run make with the corresponding file type such asmake htmlmake allprocesses all the file types implemented in sitecompiler, those being all the web content files, image & video files, and miscellaneous files.make imagesprocesses image file types.png,.jpeg,.jpg,.gif,.svg,.webp, to do these file types individually run make with the corresponding file type such asmake png.make miscprocesses miscellaneous file types:.txt,.xml,.csv,.json,.bmp,.otf,.ttf, and.webmanifest.make cleandeletes all of the.gz,.br, and.minfiles that sitecompiler produces when processing all file types.make clean-webcontentdeletes all of the.gz,.br, and.minfiles that sitecompiler produces when processing the web content file types.make clean-imagesdeletes all of the.gz,.br, and.minfiles that sitecompiler produces when processing all image file types.make sizedisplays some useful statistics about the size of files pre, and post compression.make dependruns thedependencies.shscript to install dependencies for sitecompiler.
-
To make use of the compressed
.brand.gzfiles produced by sitecompiler, the web-server may need some additional configuring to serve the compressed content.- In nginx, this involves adding the
gzip_static on;flag to serve the.gzfiles, and thebrotli_static on;flag to serve the.brfiles in versions of nginx that been compiled with https://github.com/google/ngx_brotli. - In Apache this is a bit more of a faff but there are some good tutorials around if you search for something like "Apache static compression".
- In nginx, this involves adding the
-
To make use of newer image & video codecs you may need to make some changes to the web content itself, especially when trying to maintain compatability for devices that do not support them.
- Making use of webp images is relatively simple such as what's shown here
- In HTML you can use the
<picture>and<source>attributes like this to serve either the jpg or webp depending on what the client supports<picture> <source srcset="images/picture.webp" type="image/webp"> <img src="images/picture.jpg" alt="Pretty Picture"> </picture> - In CSS you can use
modernizrand include.webpand.no-webpversions of styles like this to serve either the jpg or webp depending on what the client supports.no-webp .style-image { background-image: url("image.jpg"); } .webp .style-image { background-image: url("image.webp"); }
- In HTML you can use the
- Making use of webp images is relatively simple such as what's shown here
- Currently the
dependencies.shscript mainly relies onapt-get, and so only fully work on debian-based systems, but this wouldn't be too difficult to change in the future. - Audio encoding into the Opus format would be a nice to have
- CI for testing