apache / incubator-pagespeed-ngx

Automatic PageSpeed optimization module for Nginx
http://ngxpagespeed.com/
Apache License 2.0
4.37k stars 363 forks source link

SVG file URLs not being mapped to CDN #1670

Open andymathieson opened 4 years ago

andymathieson commented 4 years ago

Hi guys,

I'm 99% there with our Pagespeed config file. Just the SVG file URLs don't map to the CDN. All other static files do, CSS, JS, webp, jpg etc but simply not the SVG's which we use quite a lot.


<!--
<!--
mod_pagespeed on
Filters:
ah  Add Head
cc  Combine Css
jc  Combine Javascript
gp  Convert Gif to Png
jp  Convert Jpeg to Progressive
jw  Convert Jpeg To Webp
mc  Convert Meta Tags
pj  Convert Png to Jpeg
ws  When converting images to WebP, prefer lossless conversions
db  Debug
ec  Cache Extend Css
ei  Cache Extend Images
es  Cache Extend Scripts
fc  Fallback Rewrite Css 
if  Flatten CSS Imports
hw  Flushes html
ci  Inline Css
ii  Inline Images
il  Inline @import to Link
ji  Inline Javascript
js  Jpeg Subsampling
pr  Prioritize Critical Css
rj  Recompress Jpeg
rp  Recompress Png
rw  Recompress Webp
ri  Resize Images
cf  Rewrite Css
jm  Rewrite External Javascript
jj  Rewrite Inline Javascript
cu  Rewrite Style Attributes With Url
cp  Strip Image Color Profiles
md  Strip Image Meta Data

Options:
AvoidRenamingIntrospectiveJavascript (aris) True
EnableRewriting (e) 1
FileCacheInodeLimit (afcl) 500000
ImageResolutionLimitBytes (irlb) 128000000
LoadFromFileCacheTtlMs (lfct) 315360000000
LowercaseHtmlNames (lh) True
RewriteLevel (l) Core Filters
XHeaderValue (xhv) Powered By ngx_pagespeed

#NumFlushes            0
#EndDocument after     2449us
#Total Parse duration  2362us
#Total Render duration 44033us
#Total Idle duration   87us
Critical Images:
    https://domain.co.uk/assets/media/london/img/cross-white.svg
    https://domain.co.uk/assets/media/london/img/logotype-black.svg
    https://domain.co.uk/assets/media/london/img/logotype-white.svg
The following filters were disabled for this request:
    SupportNoscript
-->
Lofesa commented 4 years ago

Hi @andymathieson Can you post the whole config? You have posted the +debug, but this can´t show all the config directives.

andymathieson commented 4 years ago

Certainly. No problem.

pagespeed on;
pagespeed FileCachePath /var/ngx_pagespeed_cache;
pagespeed Disallow "*/admin*";
pagespeed Disallow "*/backend*";
pagespeed Disallow "*/grappelli*";
pagespeed Disallow *fonts.css*;
# Honoring Content-Security-Policy Headers
pagespeed HonorCsp on;
# Lower-casing HTML element and attribute names
pagespeed LowercaseHtmlNames on;
# Pagespeed Header
pagespeed XHeaderValue "Powered By ngx_pagespeed"; 
# Ensure requests for pagespeed optimized resources go to the pagespeed handler
# and no extraneous headers get set.
location ~ "\.pagespeed\.([a-z]\.)?[a-z]{2}\.[^.]{10}\.[^.]+" {
   add_header "" "";
}
location ~ "^/pagespeed_static/" { }
location ~ "^/ngx_pagespeed_beacon$" { }

pagespeed ImageResolutionLimitBytes 128000000;
pagespeed EnableFilters convert_to_webp_lossless;

pagespeed EnableFilters combine_javascript;
pagespeed EnableFilters prioritize_critical_css;
pagespeed LoadFromFileCacheTtlMs 315360000000;

pagespeed LoadFromFile 'http://domain.co.uk/assets/' '/srv/www/domainglobal/master/domainglobal/public/';

pagespeed Domain 'https://domain.co.uk/assets';
pagespeed MapRewriteDomain 'https://cdn.cloudfront.net/assets'  'https://domain.co.uk/assets';
Lofesa commented 4 years ago

Hi @andymathieson So thi´s is not working: pagespeed MapRewriteDomain 'https://cdn.cloudfront.net/assets' 'https://domain.co.uk/assets';

Well.. I´m not sure if this part work 'https://domain.co.uk/assets' as far as in the doc don´t say that path are allowed in the original domain as is stated for destination.... But you say it works for other file types.... so thi´s make me thinking is a file extension issue or an html label. The doc states "When PageSpeed rewrites a resource...." but svg files can´t be rewrited cause can´t be optimized/cache extended At what html labels are the svg files set? img or picture?

EDIT: The content-type is set to image/svg+xml ?

andymathieson commented 4 years ago

Content type is as you stated and the files are in img tags. I know these files won't optimise but I just wanted to seve via cdn

Lofesa commented 4 years ago

And when you run with the +debug parameter, Have any message about these files?

andymathieson commented 4 years ago
<img src="/assets/my.svg" alt="my-alt-tag"/><!--The image was not inlined because you have chosen to only inline the critical images but this image is not critical.-->
Lofesa commented 4 years ago

Can you try to use absolute url like: <img src="https://mydomain.com/assets/my.svg" alt="my-alt-tag"/> The other images are relatives url too?

andymathieson commented 4 years ago

Hi @Lofesa . Sorry for the late reply. I've tried with and without the absolute url but to no avail.

All other images, css, js etc is served from /assets/file.ext

Just those svgs!

Lofesa commented 4 years ago

Hi @andymathieson So this make me thinking that as far as the svg files get totally untouched by pagespeed then don´t fire the filter to change the domain. For example pdf files are not optimized in any way but the cache extender, so, I think: never tried, for pdf files the change of domain may work.

EDIT: One more thing, Have you enabled the IPRO? pagespeed InPlaceResourceOptimization on;