Keeping asset and public path different in vue app for CDN

大城市里の小女人 提交于 2020-08-10 18:30:06

问题


vue has this option publicPath which lets an app to be deployed on subpath: foobar.com/my-path , making links and every asset accessible via it.

From performance standpoint, I want to enable CDN on my application's assets. How can I use the URL specifically for assets (and not the hyperlinks)?

Example: ./my-path/assets/app.js should become https://my-staging-cdn.com/my-path/assets/app.js
./my-path/url-2.html should remain the same

The configuration below allows me to set the path and assets directory, but not able to figure out how to set cdn URL for assets

module.exports = {
  publicPath: ‘/my-path/‘,
  assetsDir: 'assets'
}

Cannot do: publicPath: process.env.NODE_ENV === 'production' ? 'https://my-staging-cdn.com/my-path' : '/my-path/', as it will change the URL in application's links too.


回答1:


Wasn't able to get the CDN working or assets out of the box. I tried other strategies like pre-rendering or Nuxt, but because of huge number of pages, it wasn't an option.

The objective was to get SEO bots to read rendered page, so I circled out on Rendertron and deployed it's instance and put it in my reverse proxy behind the application. This worked.



来源:https://stackoverflow.com/questions/61001800/keeping-asset-and-public-path-different-in-vue-app-for-cdn

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!