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, see http://en.wikipedia.org/wiki/Content_delivery_network.
Here, you’ll first discover the perks of using a CDN in Liferay DXP and learn about general guidelines for using a CDN in your Liferay DXP instance. Then, you’ll learn the steps to configure a CDN for your Liferay DXP instance. It’s time to distribute your Liferay DXP 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 specific server machine based on an algorithm. The algorithm attempts to find the 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 DXP, however, has some restrictions.
Liferay DXP only works with CDNs that can dynamically retrieve requested resources from Liferay DXP. 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 automatically fetch the content from Liferay DXP.
A Liferay DXP-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 (Liferay DXP), caches the resource, then serves the resource.
Once you’ve configured Liferay DXP 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 DXP 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 DXP, 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, Liferay DXP generates URLs to the static assets that replace the old host with your new CDN host and so they are automatically cached and served afterwards by the CDN.
To configure your CDN in the Control Panel, navigate to Control Panel → Configuration → Instance 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.
Make sure to specify your CDN host(s) with a URL that includes the protocol and domain.
CDN Host HTTP:
CDN Host HTTP:
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.