Google PageSpeed prevent image loaded by my function in Laravel

41 views
Skip to first unread message

Le Ngoc Thanh

unread,
Dec 25, 2016, 11:25:25 PM12/25/16
to ngx-pagespeed-discuss
I save uploaded image by users into Storage folder with customized path. The image's name will be parsed to know where image will be save in my Storage. Therefore, I write function to return image data when user request image by GET method. It means that image is not get directly. For example, user requests:


I get image name (in this case, d3fe6896b9dcbc02031eaf36761009c6.jpg) and parse it to know where I save the image in Storage folder. Before applying PageSpeed, image is loaded normally. However, image is not found (404 error) after I use PageSpeed for optimizing. I don't modify any PageSpeed Filters (use CoreFilters). My conf in nginx as following:

    pagespeed on;

   
# Needs to exist and be writable by nginx.  Use tmpfs for best performance.
    pagespeed
FileCachePath /var/ngx_pagespeed_cache;

   
# 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$" { }


    location
~* .(woff|eot|ttf|svg|mp4|webm|jpg|jpeg|png|gif|ico|css|js)$ {
        expires
365d;
   
}

When debugging, I see that my code for response image can not reach. 

//PHP code
//Parse image name and generate full path
//After that, get image data and response to client
$imageFile
= File::get($fullPath);    
return response($imageFile, 200)->header('Content-type', 'image/jpeg');

Therefore, I think that PageSpeed fetched image link before my code. As a result, image is not found.

How to solve the problem?



Jeff Kaufman

unread,
Jan 3, 2017, 10:16:25 AM1/3/17
to ngx-pagesp...@googlegroups.com
What happens if you set "pagespeed InPlaceResourceOptimization off" ?
> --
> You received this message because you are subscribed to the Google Groups
> "ngx-pagespeed-discuss" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to ngx-pagespeed-di...@googlegroups.com.
> Visit this group at https://groups.google.com/group/ngx-pagespeed-discuss.
> For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages