Page Rules Configurations
Caching is a useful technology to cope with the restrictions and provide a better service. Almost every electronic device has a cache for a faster connection to content.
Configuring the cache mechanism of your service at both user side and origin side is an important pinpoint and has many techniques and tools to do so. Even the websites that do not use CDN use browser caches and origin caches to reply faster.
CDN technology uses caching technology to store the origin responses to the corresponding URLs. With storing the responses in a distributed worldwide network of servers users can reach the content by connecting to the nearest server. Therefore the performance of the website is increased.
Considering the whole benefits mentioned above the idea of caching everything for a long long time appears easily. Just cache the whole website in the browser for a year to serve even faster.
But caching is permanent until the end of the Cache TTL. If you cache your whole website for a year in a browser cache that user will always reach the same content, your updates on the old contents and new contents can not be reached by that user and a non-cached browser will get an updated version of the content and two users will get different contents for the same URL for a year.
Users can delete their browsers cache manually for the updated content but it is an inefficient and inconsistent way to update a content.
So it is assured that caching a content forever is not an option but we mentioned a lot of benefits of caching too. To get the best performance from caching there must be a compromised way between caching and getting updated content.
The difference between dynamic and static components of a website appears here. There are contents that change rarely (e.g. logo of the website) and there are contents that change often (e.g. homepages, news etc.) and since we need efficiency in our caching strategy we need to configure their caches differently. Even different caching strategies can be used for subsets of these types of content.
When we add the factor we are currently only considering browser caches and ignoring the personal contents of a website, it is obvious that caching efficiently is a little bit tricky.
So we need to cache (or not cache) these contents in different configurations and different places. To achieve this flexible configuration level HTTP uses Cache-Control header.
Cache-Control header can take a lot of different and multiple values to tell the systems the content that has been received can be cached or not and if it will be cached how long it will be cached. If you’re interested in which values mean what to the caching systems you can check our "HTTP Caching" article.
Caching with MerlinCDN
We explained benefits of caching, practices of caching and HTTP’s configuration about caching. Now we come to the topic: How to configure the caching? You can write a piece of code to apply the desired configuration to the content. It is always an option but there could be times where it is hard to apply these bits to the system or there’s no resources for doing this.
Maybe there’s already a system that works with no caching involved but needs improvement performance-wise. If you are delivering your content with Merlin CDN which needs no development except a DNS redirection to start using, we got your back. In our Management Panel you will see a lot of configuration options (and not all cache related) for your content and Page Rules is the most important one to configure cache.
When we developed the Page Rules feature we aimed for flexible and easy cache configuration experience. You can use it for different paths and path parts and also different file extensions.
Since we know static and dynamic contents need different rules we add the exclusive configurations for them to make it even easier and simpler. Did you decide a new caching strategy, just add a new page rule to implement it on your desired content or change the old one. Did you implement it on the origin side just select Use Origin Cache Headers and we will respect the rules that your origin sent.
What can we configure in a Page Rule?
1- Path
You can configure the path this page rule will be applied to. It can be a folder or a full path or a file extension.
2- Connection
You can restrict the connection through Merlin CDN to the given path.
3- HTTP Methods
You can choose which HTTP methods can be used.
4- Cache TTL
You can choose a predefined selection for cache TTL (which MerlinCDN uses) or enter a custom one. We use the Origin Cache Headers in default.
5- Query String Forwarding & Caching
You may use query strings for different responses and we forward them to origin to get the correct response and cache accordingly. You can whitelist the desired query strings to make it even efficient.
6- Forward Cookies
Cookies are another element that is used in HTTP. You may need them for various reasons. You can select whether or not to receive them and also which ones you will receive.
7- Cache Based on Selected Request Headers
Request Headers may specify the content that will be delivered. If you vary your responses according to request headers we can vary our caches too.
8- Background Cache Update
We can deliver your content while updating it but since the nature of caching this content may out-dated but we promise it will be fast. If you want to serve the updated version you can select no.
9- CORS Header
Cross-Origin-Restriction may restrict your outsourced elements (e.g fonts) but you can allow them with this option.
10- Hide User Agent
You may choose to forward user agents of your visitors or not
11- Browser Cache TTL
You can specify the cache TTL for the browsers via the MerlinCDN Panel. By default it is the same as Merlin CDN’s cache TTL but if you need to adjust it differently you can. Since Merlin CDN is a shared cache layer it is advised to make it less than Merlin CDN’s cache TTL.
12- Cacheable HTTP Methods
Merlin CDN provides the choice of which methods will be cached and also we are able to cache POST requests.
13- Minimum Requests Count for Cache
If you want to cache your content when it reaches the trends you can choose how many requests we need to count before we cache. If you do not want to think about it, it is already set for 1 by default.
* This configuration is exclusive to dynamic distributions.
That’s a lot of things to configure but Merlin CDN provides the default settings that are explained above. While conserving the flexibility of caching, we simplified the rules and controls of caching into 13 input areas and they are already set to default which means to define a whole configuration all you need to do is change a few inputs.
The settings that we mentioned work for the path that is given that provides more control over the caching. You can add multiple page rules to catch the efficiency for different contents. While the contents will be cached as their corresponding rules, the Default Page Rule will be applied to all content that does not fit the given paths of other page rules.
What if a content fits multiple rules?
Flexibility is a blessing in general but in Computer Science it means problem. While it is always about steps in science, flexibility causes more roads to go. Multiple roads means a lot of things to consider and when a machine needs to consider a lot of things there is always a priority. Conditions considered with an order and we consider our page rules with an order too.
It is explained the Default Page Rule performed for every outlier. If you do not have any other rules everything is an outlier. If you have other rules we consider them first. Which order should we use? You can decide that.
In the Page Rules screen you can see the list of Page Rules. It looks like an order from newest to oldest but it is also the order that Merlin CDN will use.
We will check from top to bottom where this content fits and the first rule fits where it sits. Basically it is a priority order and you can change the priority by the interaction menu which is at the end of the row. If you move it up its priority will increase and vice versa.
Also you can move them all the way up or bottom. To conclude we provide all the choices in terms of caching to our users. Even we give the choice of using it or not and this is the simplicity we aimed for.
If you need a configuration for a content you can add a rule with every type of configuration that you can decide. You do not need to configure anything else.
If you want to handle it on the origin side, Merlin CDN already respects the headers that are sent. Your website, your customers, your rules… Merlin CDN only paves the way with network and services, it is for you to run.