A Content Delivery Network (CDN) is an interconnected system of servers deployed in multiple data centers that use geographical proximity as a criteria to deliver content across the Internet. For more information on CDNs and their general use cases and technical details, visit the following site.
First, you’ll discover the perks of using a CDN in Liferay and learn about general guidelines for using a CDN in your Liferay Portal instance. Then, you’ll learn the steps to configure a CDN for your portal. It’s time to expand your Liferay content around the world!
The CDN functions as a caching proxy. This means that once static content is copied to a local server, it is stored in a cache for quick and easy retrieval. This drastically improves latency time, because browsers can download static resources from a local server down the street instead of halfway around the world. A user’s request to the CDN for content is directed to a server machine using an algorithm. That algorithm attempts to use a server closest to the user. The figure below shows a visual representation of using geographical proximity to improve latency.
Because of the reduced wait time for requests and reduced load on your application server, a CDN is a great option to improve your portal’s performance. Using a CDN with Liferay, however, has some restrictions.
Liferay only works with CDNs that can dynamically retrieve requested resources from Liferay. Dynamic resources are resources which change over time or via interaction with end users and thus cannot be cached. For this reason, you should check with your CDN provider to make sure you don’t have to manually upload anything in order for the CDN to work. The CDN must fetch the content itself.
A Liferay-compatible CDN must work like a transparent proxy: A request first goes to the CDN. If the CDN doesn’t have the requested resource, the CDN makes an identical request back to the origin, caches the resource, then serves the resource.
Once you’ve configured Liferay to use a CDN (see below), the CDN not only serves
files referenced from a plugin’s
liferay-portlet.xml file). The CDN only
serves resources that are actually included in a plugin. It does not serve
resources that are dynamically loaded from external sources.
To get the CDN URL for a resource, developers can simply replace the portal host
in the resource path with
Developers should prefix resources with the CDN host name. They should not
manually upload any resources to the CDN or put anything on the CDN which
requires permission checking or complex policy access.
There are several properties in Liferay that enable you to configure your CDN and tweak it to suite your portal’s needs. You’ll learn how to do this next.
Now that you have a general understanding of what a CDN accomplishes and how it’s used in Liferay, it’s time to set one up for yourself. You can set your CDN and its properties using two different methods:
- By editing your portal properties file
- By using the Control Panel
To configure your CDN via properties file, you need to create a
portal-ext.properties file in your Liferay Home directory and set the
appropriate CDN properties. You can view the CDN properties and their
descriptions by visiting the Content Delivery Network
section of the
portal.properties HTML document.
Once you configure your CDN host, static assets automatically get uploaded to the CDN, and Liferay generates URLs to them that replace the old host with your new CDN host.
To configure your CDN in the Control Panel, navigate to Control Panel → Portal Settings. In the main configuration, you’ll notice three fields related to CDNs:
- CDN Host HTTP
- CDN Host HTTPS
- CDN Dynamic Resources Enabled
These properties are exactly the same as the ones you can specify in your
portal-ext.properties. Make sure to visit the CDN section of the Properties
Document referenced previously if you don’t know how to fill in the CDN fields.
Once you’re finished, click Save and your old host is replaced with your new
CDN host for static content.
As you can see, configuring a CDN is extremely easy, and can drastically reduce latency time and improve your portal’s performance.