What should you cache at the CDN servers? This is the first question that will come to your mind once you start configuring CDN caching rules for your website. The best scenario would be caching your entire website. But, unfortunately, this might not work always. Then it becomes important to decide, what you should cash and what you should not.
Caching Static objects
The most common choice is to cache Static objects which does not change at all. eg images, JavaScript, CSS files, PDF files, media files. The duration of caching will depend upon how long you think it is safe to assume that these objects are not going to change. In case this objects change, you can always flush these contents out of CDN cache.
Caching Static pages
There are many pages on your website which are pretty much static in nature. Like “Contact us”, “About us”, “Careers”. It’s a good idea to identify such pages and cache these on CDN servers. There might be other pages like your profile page, or author page, which does not change very frequently. So you can cache these pages on CDN servers for less amount of time as compared to other static contents.
Caching Dynamic pages
You should not cache Dynamic pages, in general. However, we may identify, or extract, some of the static content out of these dynamic pages and cache it on the CDN. Eg search result pages. If you notice the result, URL remains the same [mostly] and only query parameters changes. Eg below [here ?s=cdn is query string parameter]
https://www.cdnguy.com/?s=cdn
https://www.cdnguy.com/?s=best
This might be also applicable to certain product display pages where the main URL remains the same but query parameters changes. Based on different query string parameter values, the content of the page changes. So you can cache these pages for some amount of time and improve the page load time for the end users by caching it at the CDN server, and reducing load on your origin server. This will improve end users experience.
There are some CDNs that will provide you additional rules where you can identify logged in user on the basis of certain cookies, and then you can decide whether you should cache these pages or not. Take an example of this site. If you are logged in, the homepage for you will look pretty much like mine but on top you will have an Admin bar. Now, if this Admin bar is cached, then you will see the same content as I see. Most of the links in admin panel will not work for you because you are not logged in.
Also it will not be a good idea to cache admin pages because once these pages are cached, these request might not come to server at all, and will be delivered from CDN cache without authentication. You will be see those contents which you should not. Thus you should be very careful while deciding caching rules out of Dynamic pages.
Hope I answered the question “What you should cache on the CDN servers”. In case you still have any question, or you like to add anything, feel free to mention them in comment section below.