ASP.NET 4.5 имеет отличную новую функцию связывания и, похоже, имеет определенную поддержку для использования CDN. Пример, предоставленный Microsoft для использования функции связывания с CDN, - это
public static void RegisterBundles(BundleCollection bundles)
{
//bundles.Add(new ScriptBundle("~/bundles/jquery").Include(
// "~/Scripts/jquery-{version}.js"));
bundles.UseCdn = true; //enable CDN support
//add link to jquery on the CDN
var jqueryCdnPath = "http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.7.1.min.js";
bundles.Add(new ScriptBundle("~/bundles/jquery",
jqueryCdnPath).Include(
"~/Scripts/jquery-{version}.js"));
// Code removed for clarity.
}
Кажется, вам кажется, что вам нужно явно указать путь к вашему файлу на CDN.
CloudFront CDN (и я предполагаю, что многие другие) дает вам субдомен, который отражает ваши собственные. Когда вы нажмете http://uniquesubdomain.cloudfront.net/js/myfile.js?v=1
, он будет обслуживать http://mydomain.com/js/myfile.js?v=1
Таким образом вы можете просто префикс всех ваших ссылок с помощью http://uniquesubdomain.cloudfront.net/
, а ваши файлы - сервером из CloudFront.
Является ли функция связывания ASP.NET 4.5 совместимой с этим типом CDN? Есть ли встроенный способ привязки функции связывания всех своих ссылок с вашим доменом CDN?
Eg.
bundles.UseCdn = true;
var myBundle= new ScriptBundle("~/bundles/js", "https://uniquedomain.cloudfront.net/");
myBundle.Include("~/js/file1.js");
myBundle.Include("~/js/file2.js");
приведет к
<script src="https://uniquedomain.cloudfront.net/bundles/js?v=6y-qVPSK3RYOYHfPhOBDd92H4LjEjs-D3Hh2Yml6CXA1"></script>