Webp Utility (studentsv2.uit)

Webp image format is a, supported by the bulk of contemporary browsers. Rationale for using it in studentsv2.uit includes:

  • Same or better image compression compared to jpeg/png
  • Zero-worry configuration = .htaccess automatically pushes webp version of image assets if available (otherwise, serves up the original assets)
  • Google favours sites with webp support

The bash file /var/www/webp.bash contains script to automatically convert .jpgs and .pngs in /sites/default/files/images (and children directory) to .webp. This bash file is executed on an hourly basis.

How do I apply webp script in my directory?

  1. Edit /var/www/webp.bash - copy the last line, modify the line and paste your own directory
  2. Execute webp.bash (bash webp.bash)
  3. Restore /var/www/webp.bash if necessary

What is the modification in .htaccess?

<ifModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{HTTP_ACCEPT} image/webp
    RewriteCond %{REQUEST_URI}  (?i)(.*)(\.jpe?g|\.png)$
    RewriteCond %{DOCUMENT_ROOT}%1.webp -f
    RewriteRule (?i)(.*)(\.jpe?g|\.png)$ %1\.webp [L,T=image/webp,R]
</IfModule>

<IfModule mod_headers.c>
    Header append Vary Accept env=REDIRECT_accept
</IfModule>

AddType image/webp .webp

source