V8-archive: Add Cache-Control header for assets endpoint as download endpoint does

Created on 25 Dec 2019  路  10Comments  路  Source: directus/v8-archive

Hi there,

I found that v8.3.1 have set the cache control for download endpoint but not enable cache control on assets endpoint, Can we do that for assets endpoint?

enhancement question tweak

Most helpful comment

@dwene posted some thoughts on how to configure this in the duplicate issue mentioned above:


Perhaps either:

  1. Ability to add a query-param that would set the expires header. /_/assets/{hash}?key=thumbnail&cache-control=1234567
  2. New field on each directus file where you could set http cache headers. I guess this would also mean you'd need some way to configure the thumbnails.
  3. Maybe you could set global cache header on each configured thumbnail. ex: directus-large-contain should always set cache-control for 1 day, and have that be configurable in the thumbnails.

I personally prefer number 1.


I think we should implement option 3 to provide good defaults, and then consider adding 1. as a parameter for more fine-grained control 馃檪

@bjgajjar this could be a good low-hanging fruit feature to implement a little earlier. Doesn't sound too difficult to add, but gives a huge performance boost for websites relying on the asset endpoint.

All 10 comments

@directus/api thoughts?

@everyx - Are you using a proxy? As you mention the download endpoint which is for proxy's only.

@bjgajjar What is the proxy meaning, or how do I know if I'm using a proxy? the origin file down path return by api is used download endpoint to me.

{
    "data": {
        "api": {
            "version": "8.3.1",
            "requires2FA": false,
            "database": "mysql",
            "project_logo": {
                "url": "\/downloads\/xxxxxxxx\/7b7b0446-6fe0-4efc-92ab-38207234c216.svg",
                "full_url": "https:\/\/api.fengsi.io\/downloads\/xxxxxxxx\/7b7b0446-6fe0-4efc-92ab-38207234c216.svg"
            },
            "project_color": "#00662F",
            "project_foreground": {
                "url": "\/downloads\/xxxxxxxx\/7b7b0446-6fe0-4efc-92ab-38207234c216.svg",
                "full_url": "https:\/\/api.fengsi.io\/downloads\/xxxxxxxx\/7b7b0446-6fe0-4efc-92ab-38207234c216.svg"
            },
            "project_background": null,
            "default_locale": "zh-CN",
            "telemetry": true,
            "project_name": "xxxxxx",
            "project_public_note": ""
        },
        "server": {
            "max_upload_size": 67108864,
            "general": {
                "php_version": "7.4.1",
                "php_api": "fpm-fcgi"
            }
        }
    }
}

@everyx - Currently the proxy URL contains the cache-control variable. You are getting the downloads endpoint as you enabled storage.proxy_downloads; otherwise, the file origin URL will have a uploads URL.

As per my knowledge, we don't have any feature to add cache-control in directus other endpoint for now except /downloads.

@rijkvanzanten - Let me know if we are supposed to add this feature.

Lets add it 馃憤 having the thumbnails cached in the browser makes perfect sense to me

downloads endpoint contains cache-control and set a max-age as proxy_downloads_cache_ttl from directus_settings table. Right now, we dont have any variable named proxy_downloads_cache_ttl in settings table.

Let's add one variable named thumb_cache_ttl which will use for thumbnails as well as downloads

@dwene posted some thoughts on how to configure this in the duplicate issue mentioned above:


Perhaps either:

  1. Ability to add a query-param that would set the expires header. /_/assets/{hash}?key=thumbnail&cache-control=1234567
  2. New field on each directus file where you could set http cache headers. I guess this would also mean you'd need some way to configure the thumbnails.
  3. Maybe you could set global cache header on each configured thumbnail. ex: directus-large-contain should always set cache-control for 1 day, and have that be configurable in the thumbnails.

I personally prefer number 1.


I think we should implement option 3 to provide good defaults, and then consider adding 1. as a parameter for more fine-grained control 馃檪

@bjgajjar this could be a good low-hanging fruit feature to implement a little earlier. Doesn't sound too difficult to add, but gives a huge performance boost for websites relying on the asset endpoint.

+1, sounds like a good idea!

The ASSETS_CACHE_CONTROL variable is not taken into account in .env:

Screenshot_20210116_192013

Here's the asset url: https://foobar.com/assets/54a1d57a-a73a-4114-8be2-20d5050fdabf?width=1920&height=1080
And here's the response header: cache-control: public, max-age=1800000

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ondronix picture ondronix  路  3Comments

benhaynes picture benhaynes  路  4Comments

jwkellyiii picture jwkellyiii  路  3Comments

rijkvanzanten picture rijkvanzanten  路  3Comments

24js picture 24js  路  3Comments