By default, we inherit all HTTP headers set on the origin (read more on HTTP headers caching). CDN content is stored on servers according to the Cache-Control header directive (if you do not ignore origin caching settings).
Configure Origin
In order for a CDN to cache files from your origin in a proper way, they should have the Cache-control header with public and max-age directives.
Add to your server configuration the following
For Apache
<ifModule mod_headers.c> |
For Nginx
server { |
Check Settings
You can check these headers on your origin the following ways
Use the cURL command
curl -I http://example.com/images/1.jpg
HTTP/1.1 200 OK
Server: nginx/1.13.1
Date: Fri, 09 Jun 2017 12:54:24 GMT
Content-Type: image/jpeg
Content-Length: 124024
Connection: keep-alive
X-Image-Generated: 29
X-Image-Meta: 1024x768
X-Image-Read: 71
Expires: Wed, 06 Dec 2017 12:51:43 GMT
Cache-Control: max-age=15552000
Access-Control-Allow-Origin: *
Last-Modified: Sun, 01 Jan 2017 12:00:00 GMT
Cache-Control: max-age=315360000, public, immutable — file caching time specified on the origin
Cache: HIT - file is given from the cache CDN
X-Cached-Since: 2017-06-09T12:51:43+00:00 — time when the file was cached in a CDN node.
X-ID: m9-up-e245 — CDN node, which was given to file
Use your browser
Open a browser (e.g. Google Chrome) -> open your site -> press F12 (to open a developer console) -> choose the Network tab -> refresh the page (press F5). You will get the list of all files downloaded from your site. Choose one of them and on the Headers tab on the right, you’ll see the headers set on your origin.
Important HTTP Headers
Cache-control
- Max-Age — cache lifetime in seconds
- Public — the file is cacheable by clients and shared (proxy) caches.
- Private — the file is cacheable only on the client and not by shared (proxy server) caches. Do not use this directive.
- No-cache — the file will not be cached on CDN and each time will be pulled from the origin. Do not use this directive.
X-cache
- X-Cache: HIT — the file has been delivered from CDN
- X-Cache: MISS — the file has not been cached in CDN. Check your HTTP headers and control panel settings.
- X-Cached-Since: 2017-06-09T12:51:43+00:00 — time when the file was cached in a CDN node.