ASP.Net MVC 5 - Deploy separate CDN site with bundled JavaScript and CSS

孤者浪人 提交于 2020-01-15 16:52:14

问题


I was wondering whether it is possible to deploy two ASP.Net MVC sites to do the following.

  1. Main Website: contains all the controllers and views
  2. CDN website: contains all the JavaScript and CSS (bundles JS and CSS that is consumed by the first site)

I was expecting that in the solution you would have two website projects. I think in debug mode this would work fine because the bundle names are consistent.

However, in production where you are not running in debug mode (turned off in web.config), the file names have a query parameter that varies e.g. http://www.test-domain.com/bundles/bootstrap?v=2Fz3B0iizV2NnnamQFrx-NbYJNTFeBJ2GM05SilbtQU1 (where bootstrap is the name of the bundle).

Does anyone know how to reference the bundles in the CDN website from the Razor views in the main website?

Answer I realised that you don't have to include the query parameter for bundle name


回答1:


If your MVC 5 project work well in Release mode in your local machine, it will work on Production too.

Only few more considerations you need to take care on production are :

  • Make sure CORS is enabled since you have js & css resources at different site(if domain name is different)

  • Make sure you references at MVC5 site having hosting views & back-end logic have correct references as you have created in CDN

  • Firewall/hosting port is allowed on both hosting machine to communicate.

Hope this helps.

BTW querystring appended to end of URL just make sure every request is differently served by Server not as cached, nothing to impact your application.



来源:https://stackoverflow.com/questions/48145206/asp-net-mvc-5-deploy-separate-cdn-site-with-bundled-javascript-and-css

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