LiipImagineBundle: Images not resolving when browser caching is enabled

Hello,

when I enable browser caching using nginx

location ~* .(js|jpg|jpeg|gif|png|css|tgz|gz|rar|bz2|doc|pdf|ppt|tar|wav|bmp|rtf|swf|ico|flv|txt|woff|woff2|svg)$ {
expires 30d;
add_header Pragma "public";
add_header Cache-Control "public";
}

images are not resolving(only resolving when I open developer tools and tick “Disable cache while dev tools is open” in Chrome)

image

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 1
  • Comments: 17 (5 by maintainers)

Most upvoted comments

I put a specific configuration only for resolving before static files caching directive:

    # bypass thumbs cache image files
    location ~ ^/media/cache/resolve {
      expires 1M;
      access_log off;
      add_header Cache-Control "public";
      try_files $uri $uri/ /index.php?$query_string;
    }

    location ~* .(js|jpg|jpeg|gif|png|css|tgz|gz|rar|bz2|doc|pdf|ppt|tar|wav|bmp|rtf|swf|ico|flv|txt|woff|woff2|svg)$ {
        expires 30d;
        add_header Pragma "public";
        add_header Cache-Control "public";
    }

I share my experience in case it can help someone. In my case, I use an nginx web server, the configuration was :

   location ~*  \.(jpg|jpeg|png|gif|ico)$ {
        expires 365d;
        log_not_found off;
        access_log off;
    }

The thing is that with such a configuration, the image is not found and nginx does not try to go any further. I added : try_files $uri $uri/ /index.php?$query_string; for liip to be able to generate the cache as it is supposed to do. With this new line, if the image is not present, index.php is hit with the query string that corresponds to the image and liip can do its job.

My server configuration is then :

   location ~*  \.(jpg|jpeg|png|gif|ico)$ {
        expires 365d;
        log_not_found off;
        access_log off;
        try_files $uri $uri/ /index.php?$query_string;
    }

You can check :

  • /vendor/liip/imagine-bundle/Resources/config/routing.yaml
  • /vendor/liip/imagine-bundle/Controller/ImagineController.php

I am nor symfony, nor nginx guru, therefore, there can be some better way to achieve that.

PS : it works on symfony 5 with LiipImagineBundle 2.3

It took almost two days for me to debug the same crap. I’m so surprised to see so many people have the same problem here.

There is no such settings as verbose mode for logging & debugging, I’m quite clueless, such a waste of time.

No I don’t need any special support. It just feels like this bundle is dead and not supported, no one is giving any comments in “issues” section. I’ll look at this later, since I had to uninstall this bundle and do it myself and my way.

Btw. this guy probably has the same issue #1252 , but again no response.

is this bundle dead?

no, but it is open source and people work on it as they find time. if you need payed support with strict response time, you should ask for that…

the question you ask is very specific and might be an unlucky interaction between nginx and how the imagine bundle works. or something that is not related to the bundle. afaik the first time you request an image, a redirect happens to generate that image. but in the end, assuming you do see an image on a first page load, i don’t see why the browser would cache a broken response. did you debug the process to see what goes wrong?

I’m using version ^2.3