Skip to main content
Version: 2.x

Serving assets from a CDN/custom domain

Since version 2.7

You may want to use a different domain for your assets for several reasons. This guide explains how to configure this in a Front-Commerce application.

Configuration

Serving assets from a custom domain can be done with a configuration change:

  1. for each store in config/stores, you can add a assetsBaseUrl entry so that static assets and images are served from it. For instance:

    module.exports = {
    default: {
    url: process.env.FRONT_COMMERCE_URL,
    assetsBaseUrl: "http://a.cdn.example.com",
    locale: "en-US",
    currency: "EUR",
    default_country_id: "GB",
    countries: (IsoCountries) =>
    IsoCountries.registerLocale(
    require("i18n-iso-countries/langs/en.json")
    ),
    },
    };

    In a multiple store setup, it's possible to use the same assetsBaseUrl for all stores.

  2. Configure the CSP so that assets can be loaded from this external URL

  3. You might also have to allow this domain in CORS origins to prevent "has been blocked by CORS policy" errors

After restarting Front-Commerce, your assets should be loaded from this custom domain.

note

The assetsBaseUrl configuration only effects your production environment. In the development environment, your assets will still be served from the root of your application.