[GH-ISSUE #85] Include caching headers when serving image files #63

Closed
opened 2026-02-25 23:40:33 +03:00 by kerem · 8 comments
Owner

Originally created by @thomasjsn on GitHub (Mar 8, 2019).
Original GitHub issue: https://github.com/HaschekSolutions/pictshare/issues/85

It would be beneficial if caching headers were part of the response when serving image files;

Cache-control: public, max-age=31536000

As these files should be pretty much immutable. I can submit a pull request for this, if you point me to suitable method where this should be handles.

Originally created by @thomasjsn on GitHub (Mar 8, 2019). Original GitHub issue: https://github.com/HaschekSolutions/pictshare/issues/85 It would be beneficial if caching headers were part of the response when serving image files; Cache-control: public, max-age=31536000 As these files should be pretty much immutable. I can submit a pull request for this, if you point me to suitable method where this should be handles.
kerem closed this issue 2026-02-25 23:40:33 +03:00
Author
Owner

@thomasjsn commented on GitHub (Mar 8, 2019):

Ok, just an update, I added the following in my nginx config to set caching headers for images and videos.

    location ~ \.php {
        fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
        fastcgi_index index.php;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param PATH_INFO $fastcgi_script_name;

        if ($request_uri ~ \.(?:ico|gif|jpe?g|png|webp|bmp|mp4)$) {
            add_header Cache-Control "public";
            expires max;
        }   
    }   

Maybe just include this in the documentation and leave setting the cache headers out of the php code?

<!-- gh-comment-id:471091489 --> @thomasjsn commented on GitHub (Mar 8, 2019): Ok, just an update, I added the following in my nginx config to set caching headers for images and videos. ``` location ~ \.php { fastcgi_pass unix:/var/run/php/php7.2-fpm.sock; fastcgi_index index.php; include fastcgi_params; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param PATH_INFO $fastcgi_script_name; if ($request_uri ~ \.(?:ico|gif|jpe?g|png|webp|bmp|mp4)$) { add_header Cache-Control "public"; expires max; } } ``` Maybe just include this in the documentation and leave setting the cache headers out of the php code?
Author
Owner

@dessalines commented on GitHub (Sep 8, 2019):

Would be good to add this to the nginx config here

<!-- gh-comment-id:529229315 --> @dessalines commented on GitHub (Sep 8, 2019): Would be good to add this to the nginx config [here](https://github.com/HaschekSolutions/pictshare/blob/master/rtfm/INSTALL.md)
Author
Owner

@dessalines commented on GitHub (Sep 8, 2019):

I've found that I can't get this working with docker and a proxy_pass. Been trying things like a proxy_cache for a few hours...

<!-- gh-comment-id:529236014 --> @dessalines commented on GitHub (Sep 8, 2019): I've found that I can't get this working with docker and a proxy_pass. Been trying things like a proxy_cache for a few hours...
Author
Owner

@dessalines commented on GitHub (Sep 8, 2019):

These are the only headers pictshare is returning when using the proxy_pass with docker:

{"name":"content-type","value":"image/png"},
{"name":"date","value":"Sun, 08 Sep 2019 19:58:33 GMT"}
"name":"server","value":"nginx"},
{"name":"X-Firefox-Spdy","value":"h2"}]}}

Its missing etag, cache-control, age

<!-- gh-comment-id:529236657 --> @dessalines commented on GitHub (Sep 8, 2019): These are the only headers pictshare is returning when using the proxy_pass with docker: ``` {"name":"content-type","value":"image/png"}, {"name":"date","value":"Sun, 08 Sep 2019 19:58:33 GMT"} "name":"server","value":"nginx"}, {"name":"X-Firefox-Spdy","value":"h2"}]}} ``` Its missing etag, cache-control, age
Author
Owner

@geek-at commented on GitHub (Sep 23, 2019):

My idea was that your reverse proxy can manage the cache. I didn't include it in the actual image because caching could have the unwanted side effect that it will be still accessible after you deleted it

<!-- gh-comment-id:534224475 --> @geek-at commented on GitHub (Sep 23, 2019): My idea was that your reverse proxy can manage the cache. I didn't include it in the actual image because caching could have the unwanted side effect that it will be still accessible after you deleted it
Author
Owner

@dessalines commented on GitHub (Oct 20, 2019):

Unfortunately the reverse proxy can't do the caching, it needs to be done in the actual docker nginx config.

<!-- gh-comment-id:544219605 --> @dessalines commented on GitHub (Oct 20, 2019): Unfortunately the reverse proxy can't do the caching, it needs to be done in the actual docker nginx config.
Author
Owner

@dessalines commented on GitHub (Jan 4, 2020):

I'm still stuck on this, has anyone gotten pictshare caching to work?

<!-- gh-comment-id:570736637 --> @dessalines commented on GitHub (Jan 4, 2020): I'm still stuck on this, has anyone gotten pictshare caching to work?
Author
Owner

@Nutomic commented on GitHub (Jun 3, 2020):

FYI you can do this with the following nginx config:

if ($request_uri ~ \.(?:ico|gif|jpe?g|png|webp|bmp|mp4)$) {
    add_header Cache-Control "public, max-age=31536000, immutable";
}   
<!-- gh-comment-id:638100664 --> @Nutomic commented on GitHub (Jun 3, 2020): FYI you can do this with the following nginx config: ``` if ($request_uri ~ \.(?:ico|gif|jpe?g|png|webp|bmp|mp4)$) { add_header Cache-Control "public, max-age=31536000, immutable"; } ```
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/pictshare#63
No description provided.