Skip to content

Instantly share code, notes, and snippets.

@HoffmannP
Last active August 29, 2015 14:20
Show Gist options
  • Save HoffmannP/9aaeccaebdea3495a872 to your computer and use it in GitHub Desktop.
Save HoffmannP/9aaeccaebdea3495a872 to your computer and use it in GitHub Desktop.
less cached for Lighttpd
#!/bin/sh
if [ -z "$1" ]; then
exit 1
fi
echo "/* Using less-cache */"
id="$(sha512sum "$1" | cut -d' ' -f1)"
file="/tmp/less.${id}.css"
now=$(date +%s)
if [ ! -e "$file" ]; then
# requires lessc and clean-css
/usr/bin/lessc --clean-css="--s0" "$1" > "$file"
chmod ugo+rwx "$file"
fi
cat $file
echo "/* less-cache took "$(expr $(date +%s) - $now)"s */"
exit 0
# Configuration for Lighttpd:
# server.modules += ( "mod_cgi" )
# cgi.assign += (
# ".less" => "/usr/local/bin/less-cache",
# )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment