Content Delivery Network (CDN) is a network with servers that reduces the network traffic to your primary server(s). A CDN network often has multiple servers and the different servers are placed around the world. You, as a client, will be using the server located closest to you, depending on your IP address. The reason is that data should be sent as short distances as possible to ensure the highest possible speed.
What is Content Delivery Network (CDN)?
There are many types of CDN. The two most common ones are described here.
- The simplest one is when you manually upload files to the CDN, and then the CDN is served with the uploaded files.
- The second one is called edge-caching, in which the CDN is automatically populated with files from an origin server. This means that the first request from PoPs (point of presence) downloads content from the main server.
Example: The main site is www.litium.se and a CDN is created with the domain cdn.litium.se. For every request sent to cdn.litium.se, where the CDN does not have the requested file, the CDN downloads the file from www.litium.se and caches it based on the cache-header included in the response. For all subsequent requests for the same file, the CDN already has the file cached and can serve directly with the cached content.
Does Litium support CDN?
Yes, Litium has built-in support for edge-cache CDN to reduce the number of requests for all anonymously accessible files and/or images stored inside the product. All requests not accessed by anonymous users will be served directly by Litium as before, to be able to access control of the files.
How does this work inside Litium?
When activating the CDN support for edge-cache all file links are re-written to include the domain name for your edge-cache domain, like in the example above, cdn.litium.se.
I have static files in a folder on the site. Can I use edge-cache for them too?
Yes, you can. In Litium there is a built-in CDN filter that will parse the response and add a hostname to the static file names.
E.g. change tags from:
<img src="/ui/img/image.jpg" />
To:
<img src="http://cdn.litium.se/ui/img/image.jpg" />
How do I activate the CDN support?
Create an account at a CDN supplier
Start by creating an account at a CDN supplier and setup the CDN. The CDN should probably point directly to your main domain as origin server. Go to www.cdnfinder.com for a selection of CDN suppliers.
Configuration in Litium
After you have created your account at the CDN supplier you need to setup Litium. All configurations that you need to change are in the web.config. (If you don't intend to use the CDN filter you can skip those steps.)
- Open the web.config.
- Add the attribute useCdn="true" and cdnHost="cdn.litium.se" (replace cdn.litium.se with your CDN domain name) to the storage element. The element should now look like this:
<storage cdnHost="cdn.litium.se" useCdn="true" />
- If your CDN supports secure content (https) you should also add the attribute useCdnForSecureContent="true", otherwise requests for secure content will not be directed to the CDN, in order to avoid broken images on your site. If your CDN for secure content is not the same as for non-secure content you can specify the secure content CDN with the attribute cdnSecureHost="ssl-cdn.litium.se".
- Find the element cdnFilter inside the section litium\studio. If the section is not found you should add the section and configure it with your settings. To be able to use this section the section needs to be declared in the declarations of the studio section with <section name="cdnFilter" type="Litium.Studio.Configuration.CdnFilterSection, Litium.Studio" />.
<cdnFilter>
<hosts>
<add host="http://cdn-axd.litium.se" secureContentHost="https://secure-cdn.litium.se">
<matches>
<add match="src="/WebResource.axd" />
<add match="src="/ScriptResource.axd" />
</matches>
</add>
<add host="http://cdn-ui.litium.se">
<matches>
<add match="href="/ui/" />
<add match="src="/ui/" />
<add match="background-image:url('/ui/" insertAfter="'" />
</matches>
</add>
</hosts>
</cdnFilter>
- The attribute secureContentHost is optional and if the attribute is excluded replacements when browsing secure content (https) pages are also excluded.
- The attribute insertAfter is optional and if excluded the default " is used.
In the above example we make several redirects to different hosts as an example for multiple matches to different hosts.
- Save and close your web.config.
Multiple domain hosts for CDN
If you need to speed up the loading of content from the CDN you can use several CDN's, e.g. cdn1.litium.se, cdn2.litium.se, cdnN.litium.se to reduce the number of requests to a single hostname. Why should I use multiple CDN domains? Browsers are built to only make a limited number of simultaneous requests to each domain name. By using multiple domain names you can get faster response times.
To enable multiple hosts for storage you simply put multiple hosts in the cdnHost and/or cdnSecureHost attribute separated by commas (,). Litium is built to spread the requests among the CDN hosts but always use the same host for the same file.
Multiple domain hosts for CDN are only available for storage, not cdn-filter.
|