This script creates headers of all files in a given directory to use them for HTTP/2 server push.
Usage: linkheader.sh /mydir
This script creates headers of all files in a given directory to use them for HTTP/2 server push.
Usage: linkheader.sh /mydir
#!/bin/sh | |
# Creates Link headers of all asset files in a directory. | |
# | |
# LICENSE: CC0/Public Domain - To the extent possible under law, rugk has waived all copyright and related or neighboring rights to this work. This work is published from: Deutschland. | |
getfiletype() { | |
fileext=${1##*.} | |
case $fileext in | |
js) | |
echo "script" | |
;; | |
css) | |
echo "stylesheet" | |
;; | |
jpg|jpeg|png|gif) | |
echo "image" | |
;; | |
esac | |
} | |
for asset in $1/*; do | |
assetfile=$( basename "${asset}" ) | |
filetype=$( getfiletype "${assetfile}" ) | |
if [ "${filetype}" != "" ]; then | |
echo "Link <$1/${assetfile}>; rel=preload; as=${filetype}" | |
fi | |
done |