Browsers usually restrict the maximum amount of parallel loads from a given subdomain. Therefore, I want to spread asset loading across 4 CDNs:
Using something like this (based on the file name) to determine the cdn number:
"/static/media/asset-name.6d24aee6.png".split('').reduce((a, b) => a + b.charCodeAt(0), 0) % 4
How can I do this in Razzle?
So far, this is what I have. In razzle.config.js
:
const PUBLIC_PATH = process.env.PUBLIC_PATH || '/';
module.exports = {
modify: (config, { dev, target }, webpack) => {
if (!dev) {
config.devtool = false;
// Use the CDN in production
config.output = {
publicPath: PUBLIC_PATH
};
}
config.plugins.push(
new webpack.DefinePlugin({
'process.env.PUBLIC_PATH': JSON.stringify(PUBLIC_PATH)
}),
}
}