0VPS Tweaks pour améliorer les performances web

Alors que je ne l'ai pas écrit de nombreux nouveaux articles récemment, j'ai passé beaucoup de temps la mise à jour et la révision du côté derrière les coulisses des choses, à savoir différents services de sécurité (TLS) paramètres de mon VPS qui héberge plusieurs sites dont celui-ci. Une autre chose que j'ai aussi travaillé à améliorer est récemment pour améliorer mon utilisation de gzip, et un nouveau format appelé Brötli

Brièvement, gzip (et Brötli) can be used to com­press resources before they are sent to the browser, ce qui réduit la quantité de données envoyées, and hence should mean a site loads faster. The down­side is that com­press­ing resources takes time, which could out­weigh the gains from the smal­ler sizes. The ideal solu­tion is to have resources com­pressed in advance, rather than com­pressed by the http serv­er in real­time. Most of my web­sites use word­press which con­tains lots of files in plu­gins, thèmes, etc., so going through all of these and manu­ally com­press­ing them everytime there is an update would be imprac­tic­al. The answer is to use a script which mon­it­ors the sys­tem for file changes, and cre­ates com­pressed files as needed. Below is the script I have recently writ­ten to do exactly this.

#!/bin/bash                               

inotifywait -m -q -e CREATE -e MODIFY -e MOVED_TO -r "/var / www /" --format "%w% f" -- » Excludei.(jpg|png|gif|ico|bûche|sql|code postal|gz|pdf|php|swf|ttf|EOT|woff|cst|JST|br|EVC)$» |
while read file
do
if [[ $file = ~ \.(css)$ ]];
then
fname="${fichier%.*}"
si [ -fa "$FNAME".min.css ]
then
rm -f $file.gz
rm -f $file.br
zopfli --gzip $file
bro --quality 11 --input $file --output $file.br
chmod 664 $file.br
chmod 664 $file.gz
chown wordpress:wordpress $file.br
chown wordpress:wordpress $file.gz
else
rm -f $file.gz
rm -f $file.br
cat $file | CleanCSS > $fname.cst
cat $file | CleanCSS | bro --Quality 11 --output $file.br
zopfli --gzip $fname.cst -c > $fname.css.gz
chmod 664 $file.br
chmod 664 $file.gz
chown wordpress:wordpress $file.br
chown wordpress:wordpress $file.gz
rm -f $fname.cst
fi
fi

if [[ $file = ~ \.(js)$ ]];
then
fname="${fichier%.*}"
si [ -fa "$FNAME".min.css ]
then
rm -f $file.gz
rm -f $file.br
zopfli --gzip $file
bro --quality 11 --input $file --output $file.br
chmod 664 $file.br
chmod 664 $file.gz
chown wordpress:wordpress $file.br
chown wordpress:wordpress $file.gz
else
rm -f $file.gz
rm -f $file.br
uglifyjs $fname.js > $fname.jst
zopfli --gzip $fname.jst -c > $fname.js.gz
bro --quality 11 --input $fname.jst --output $file.br
chmod 664 $file.br
chmod 664 $file.gz
chown wordpress:wordpress $file.br
chown wordpress:wordpress $file.gz
rm -f $fname.jst
fi
fi

origfs=$(wc -c < "$dossier")
gzfs = $(wc -c <"$fichier.gz")
BRFS = $(wc -c <"$file.br")

si [ "$origfs" -lt "$gzfs" ];
then
rm $file.gz -f
fi
if [ "$origfs" -lt "$BRFS" ];
then
rm $file.br -f
fi

done

Laisser un commentaire