浏览器通常会限制来自给定子域的最大并行负载量。因此,我想将资产加载分散到 4 个 CDN 上:
使用类似这样的东西(基于文件名)来确定 CDN 号:
"/static/media/asset-name.6d24aee6.png".split('').reduce((a, b) => a + b.charCodeAt(0), 0) % 4
我怎样才能在 Razzle 中做到这一点?
到目前为止,这就是我所拥有的。在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)
}),
}
}