Disable mod_pagespeed compression for a specific image file
Asked Answered
C

2

7

I'm using Apache with mod_pagespeed. For some reason I can't figure out, mod_pagespeed thinks an image is much smaller than it actually is, which means once the image gets scaled up, it's really blurry.

The image in question is a CSS background-image.

Is there a way to disable mod_pagespeed image compression for a specific file?

Cinquain answered 18/8, 2016 at 8:15 Comment(0)
C
1

The mod_pagespeed documentation was not clear on this - my impression was that ModPagespeedDisallow only works for URLs containing HTML, but they also seem to work for individual files:

<IfModule pagespeed_module>
    ModPagespeedDisallow "https://www.example.com/assets/image.jpg"
</IfModule>

Put this in apache2's configuration somewhere. We put it in the virtualhost configuration in /etc/apache2/sites-available.

Cinquain answered 21/10, 2016 at 10:7 Comment(0)
H
7

I would recommend that you use data-pagespeed-no-transform like <img src="do-not-modify.png" data-pagespeed-no-transform /> to get the effect you want for that single image. You might have to use <div style="background-image: url(../images/do-not-modify.png); height: 200px; width: 400px;" data-pagespeed-no-transform></div> or similar if background gives you trouble. The main reason seems to be that PageSpeed cannot figure out the image height/width. Source: Google PageSpeed tools

Heeler answered 27/8, 2016 at 21:27 Comment(1)
Great tip! Unfortunately in this case we did not have access to the HTML and could not (easily) modify it.Cinquain
C
1

The mod_pagespeed documentation was not clear on this - my impression was that ModPagespeedDisallow only works for URLs containing HTML, but they also seem to work for individual files:

<IfModule pagespeed_module>
    ModPagespeedDisallow "https://www.example.com/assets/image.jpg"
</IfModule>

Put this in apache2's configuration somewhere. We put it in the virtualhost configuration in /etc/apache2/sites-available.

Cinquain answered 21/10, 2016 at 10:7 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.