• Resolved IdeFixx

    (@idefixx)


    Hello,

    Is it somehow possible to load WebP images on a static website? In my case I use Simply Static plugin.

    So, if I have already generated WebP images on my non-public website, I can copy them to a public website. That should not be a problem. But then I have to add some extra rules to a public .htaccess file – change mime types, right?

Viewing 9 replies - 1 through 9 (of 9 total)
  • Plugin Author Mateusz Gbiorczyk

    (@mateuszgbiorczyk)

    Hi @idefixx,

    Thank you for your message.

    I haven’t tested such a solution, but I will tell you a few things that may be useful to you:

    • original images are stored in the /wp-content/uploads/ directory
    • converted to WebP and to AVIF files are stored in the /wp-content/uploads-webpc/uploads/ directory
    • the plugin creates rules in .htaccess file in the /wp-content/ directory

    If you map the same directory structure and copy the rules from the .htaccess file it should work. If you have a different directory structure, you should change the rules in the .htaccess file accordingly.

    Best,
    Mateusz

    Thread Starter IdeFixx

    (@idefixx)

    Hi @mateuszgbiorczyk,

    Thank you so much for a quick and clear answer. I appreciate it.

    I will give it a try. 😉

    Thread Starter IdeFixx

    (@idefixx)

    Hi Mateusz,

    I believe I’m little bit closer to the final solution. But my knowledge of rewrite rules is just basic (copy/paste – honestly). Could you spare a minute and help me with it, please?

    Original image URL example:

    https://example.com/wp-content/uploads/image.jpg

    .htaccess rule:

    RewriteCond %{HTTP_ACCEPT} image/webp
    RewriteCond %{REQUEST_FILENAME} -f
    RewriteCond %{DOCUMENT_ROOT}/wp-content/uploads-webpc/$1.jpg.webp -f
    RewriteRule (.+)\.jpg$ /wp-content/uploads-webpc/$1.jpg.webp [NC,T=image/webp,L]

    Creates this URL:

    https://example.com/wp-content/uploads-webpc/wp-content/uploads/image.jpg.webp

    But it should be:

    https://example.com/wp-content/uploads-webpc/uploads/image.jpg.webp

    So, here’s just a slight problem with doubled /wp-content/ in destination URL?

    BTW. I’ve used https://htaccess.madewithlove.com to test the htaccess rule above.

    Thread Starter IdeFixx

    (@idefixx)

    Ah, a complete path to the file must be used.

    RewriteRule ^wp-content/uploads/(.*)$ /wp-content/uploads-webpc/uploads/$1.webp [NC,T=image/webp,L]

    😉

    Plugin Author Mateusz Gbiorczyk

    (@mateuszgbiorczyk)

    @idefixx So everything works fine now?

    Thread Starter IdeFixx

    (@idefixx)

    @mateuszgbiorczyk Well, not yet, I’ve to check .htaccess file with my webhosting provider technical support. Webserver still delivers .jpg/.png files instead of .webp files.

    Here is .htaccess rule which (should) redirects .jpg to .jpg.webp files:

    RewriteCond %{HTTP_ACCEPT} image/webp
    RewriteCond %{REQUEST_FILENAME} -f
    RewriteCond %{DOCUMENT_ROOT}/wp-content/uploads-webpc/$1.jpg.webp -f
    RewriteRule ^wp-content/uploads/(.+)\.jpg$ /wp-content/uploads-webpc/uploads/$1.jpg.webp [NC,T=image/webp,L]

    BTW. webhosting is still the same as for non-prod website where’s no problem with .webp images.

    Plugin Author Mateusz Gbiorczyk

    (@mateuszgbiorczyk)

    @idefixx The plugin does not change the URLs – they remain the same. Below I have attached the tutorial describing how to test the plugin:
    https://mattplugins.com/docs/how-to-test-converter-for-media-plugin

    Thread Starter IdeFixx

    (@idefixx)

    Thank you, @mateuszgbiorczyk, for reminding me your tutorial how to test it. It’s really easy to get it working with Simply Static plugin (v. 3.0.9):

    1. Additional directory must be included in General settings > Include: [your webserver path]/wp-content/uploads-webpc/uploads/
    2. Copy .htaccess files from non-prod to prod from /wp-content/ and /uploads/
    3. Test it; e.g. via PageSpeed Insights – Serve images in next-gen formats

    That’s it. 😉

    P.S.: AVIF image format works too.

    • This reply was modified 2 years, 5 months ago by IdeFixx.
    Plugin Author Mateusz Gbiorczyk

    (@mateuszgbiorczyk)

    @idefixx Thank you for the confirmation and for your tutorial!

Viewing 9 replies - 1 through 9 (of 9 total)

The topic ‘How to get it working on a static website?’ is closed to new replies.