Magento Open Source 2.1.x
Using a Content Delivery Network

Storing media files in a CDN is another alternative supported in Magento. There is no full integration with a specific CDN, and you are responsible for choosing and configuring a CDN on your own.

After configuring the CDN, you must complete the configuration from the Admin. The changes can be made at either the global or website level. When a CDN is used for media storageA dedicated space on the content delivery network for your store's assets., all paths to media on store pages are changed to the CDN paths that are specified in the configuration.

CDN Workflow
  • Browser requests media. A page from the store opens in the customer’s browser, and the browser requests the media that is specified in the HTML.

    Request sent to CDN; images found and served. The request is sent first to the CDN. If the CDN has the images in storage, it serves the media files to the customer's browser.

    Media not found, request sent to Magento web server. If the CDN doesn’t have the media files, the request is sent to the Magento web server. If the media files are found in the file system, the web server sends them to the customer’s browser.

Important! For security, when a CDN is used as media storage, JavaScript may not function properly if the CDN is located outside of your subdomain.

To configure a content delivery network:

On the Admin sidebar, tap Stores. Then under Settings, choose Configuration.

In the panel on the left under General, choose Web.

In the upper-left corner, set Store View as needed.

Expand the Base URLs section. Then, do the following:

Update the Base URL for Static View Files with the URL of the location on the CDN where static view files are stored.

Update the Base URL for User Media Files with the URL of the JavaScript files on the CDN.

Both these fields can be left blank, or can start with the placeholder: {{unsecure_base_url}}

Expand the Base URLs (Secure) section.

Update the Secure Base URL for Static View Files with the URL of the location on the CDN where static view files are stored.

Update the Secure Base URL for User Media Files with the URL of the JavaScript files on the CDN.

Both these fields can be left blank, or can start with the placeholder: {{unsecure_base_url}}

When complete,tap Save Config.