Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

itinerix's avatar

Faster image downloads?

I use a good server, but the images of my web app are slow to load... Without a CDN, how to speed this up? Cache them?

0 likes
3 replies
Sinnbeck's avatar
Sinnbeck
Best Answer
Level 102

Can you give an example? Are you sure that they are compressed and in a proper format? Ensure that they are never bigger than they need to be.

But you should be able to cache them in nginx like this

location ~* \.(?:ico|css|js|gif|jpe?g|png)$ {
    expires 30d;
    add_header Vary Accept-Encoding;
    access_log off;
}

Example borrowed from here: https://stackoverflow.com/a/20843725/1305117

1 like
itinerix's avatar

@Sinnbeck Thank you for your perfect answer on how to enable server-based cache for images!

martinbean's avatar

@itinerix How big are the images? How many are you loading on a page? Like, define “slow” 🤷‍♂️

We need specifics. You can’t just say “images are slow” and expect us to know why or what to do to remedy it.

Please or to participate in this conversation.