问题描述
我使用的<$c$c>Microsoft.AspNet.Web.Optimization$c$c>命名空间(例如 @ Styles.Render(〜/内容/静态/ CSS)
)。
我想结合一个的Windows Azure CDN使用它。
I'd like to use it in combination with a Windows Azure CDN.
我看着编写自定义 BundleTransform
但内容不是最优化的还没有。
I looked into writing a custom BundleTransform
but the content is not optimized there yet.
我也看了成解析及上传运行优化的流,但感觉就像一个黑客攻击我,我真的不喜欢它:
I also looked into parsing and uploading the optimized stream on runtime but that feels like a hack to me and I don't really like it:
@StylesCdn.Render(Url.AbsoluteContent(
Styles.Url("~/content/static/css").ToString()
));
public static IHtmlString Render(string absolutePath)
{
// get the version hash
string versionHash = HttpUtility.ParseQueryString(
new Uri(absolutePath).Query
).Get("v");
// only parse and upload to CDN if version hash is different
if (versionHash != _versionHash)
{
_versionHash = versionHash;
WebClient client = new WebClient();
Stream stream = client.OpenRead(absolutePath);
UploadStreamToAzureCdn(stream);
}
var styleSheetLink = String.Format(
"<link href=\"{0}://{1}/{2}/{3}?v={4}\" rel=\"stylesheet\" type=\"text/css\" />",
cdnEndpointProtocol, cdnEndpointUrl, cdnContainer, cdnCssFileName, versionHash
);
return new HtmlString(styleSheetLink);
}
我
如何能自动上传捆绑和缩小的版本,我的Windows Azure CDN?
How can I upload the bundled and minified versions automatically to my Windows Azure CDN?
推荐答案
因此,有没有目前这样做的好方法。我们设想的较长期的工作流程是将构建时捆绑的支持。然后,你会运行构建任务(或运行exe文件,如果你preFER)生成包,然后可以将这些上传到AzureCDN。最后,你只需打开UseCDN在BundleCollection,和脚本/样式佣工也只是自动切换到呈现出与适当的后备链接到您的AzureCDN到本地包。
So there isn't a great way to do this currently. The longer term workflow we are envisioning is adding build-time bundling support. Then you would run a build task (or run an exe if you prefer) to generate the bundles and then be able to upload these to the AzureCDN. Finally, you just turn on UseCDN on the BundleCollection, and the Script/Style helpers would just automatically switch to rendering out links to your AzureCDN with proper fallback to your local bundles.
在短期内,我认为你正在试图做的就是上传你的包到AzureCDN当束首先构造?
For the short term, what I think you are trying to do is upload your bundle to the AzureCDN when the bundle is first constructed?
一个BundleTransform是做我想,它的一个黑客位的一种方式,但你可以添加最后组合中的一个BundleTransform。自去年的BundleResponse.Content实际上是最后的捆绑包响应。在那个时间点,你可以把它上传到您的CDN。这是否有意义?
A BundleTransform is one way to do it I guess, its a bit of a hack, but you could add a BundleTransform last in your bundle. Since its last, the BundleResponse.Content is effectively the final bundle response. At that point in time you can upload it to your CDN. Does that make sense?
这篇关于如何捆绑和缩小的文件上传到Windows Azure CDN的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!