策略在Azure上的JavaScript文件 [英] Strategy for JavaScript files on Azure

查看:103
本文介绍了策略在Azure上的JavaScript文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我工作的一个战略上的Azure(ASP.NET Web角色),存储和部署JavaScript文件
我的要求是:

I am working on a strategy for storing and deploying JavaScript files on Azure (ASP.NET web role) My requirements are:


  1. 要在生产中使用缩小的版本

  2. 使用开发环境原始版本(即不缩小的)本地版(简化调试)

  3. 简单的构建/部署过程(VS2010)

  4. 简单的更新过程
  5. (我的文件从时间到时间变化)
  1. To use minified versions in production
  2. Use original versions (i.e. not minified) local versions in development environment (to simplify debugging)
  3. Simple build/deployment process (VS2010)
  4. Simple update process (my files will change from time-to-time)

这里有<一的大讨论href=\"http://stackoverflow.com/questions/2364644/visual-studio-2010-publish-minified-javascript-files-instead-of-the-original-one\">Visual Studio 2010中:发布​​缩小的JavaScript文件,而不是原有的的但是这并没有考虑到的Azure可以提供或多个实例的工作的好处

There is a great discussion here Visual Studio 2010: Publish minified javascript files instead of the original ones however this does not take into account the benefits Azure can offer or working with multiple instances.

我正在考虑部署我的精缩的JavaScript文件BLOB存储并在生产版本中使用它们。这些将被存储与客户端缓存和文件名将存储的版本(这样我就可以轻松地更新)大的max-age缓存控制。我欢迎反馈这一战略。

I am considering deploying my minified JavaScript files to blob storage and use these in the production version. These will be stored with a large max-age Cache Control for client side caching and filenames will store the version (so I can easily update). I welcome feedback on this strategy.

因此​​,在发展中呈现的HTML将指向本地脚本文件,即:

Thus, in development the rendered HTML would refer to a local script file, i.e.:

<script src="Scripts/myjavascript-0.0.1.js" type="text/javascript"></script>

但在生产的结果应使用以下方法来指缩小的版本。

But in Production the result should use the following to refer to a minified version.

<script src="http://myblob.blob.core.windows.net/Scripts/myjavascript-0.0.1.js" type="text/javascript"></script>

我的主要问题,虽然是如何最好地实现研发和生产路径的自动切换。或将自定义处理程序是正常的路由(如果这样会怎样的工作 - 我不希望每个实例从每个请求的BLOB重新加载)。

My main question though is how to best to achieve automatic switching of the paths in development and production. Or would a custom handler be the normal route (and if so how would that work – I don’t want each instance to reload from the blob on each request).

推荐答案

关于#1安培; 2:

我讨论这个<一个战略href=\"http://stackoverflow.com/questions/1297024/yui-com$p$pssor-and-net-apps/1297065#1297065\">here.其基本思路是,以用户辅助函数来发出脚本标签。该功能可以构建一个链接到调试文件在调试模式下时,和缩小的文件,否则(这也可以很容易地与缩小的文件进行本地测试)。同样的功能,可以处理增加一个版本为缓存失效等路径。

I discuss a strategy for this here. The basic idea is to user a helper function to emit the script tag. The function can construct a link to the debug files when in debug mode, and the minified files otherwise (which also makes it easy to test locally with the minified files). The same function can handle adding a version to the path for cache invalidation, etc.

关于#3:

添加微小作为一个后生成步骤。我说这我的的csproj (这只是一个MSBuild文件),它使用YUI-COM pressor:

Add the minification as an after-build step. I added this to my csproj (which is just an msbuild file), which use yui-compressor:

<Target Name="AfterBuild" Condition="'$(Configuration)' != 'Debug'">
  <!-- remove previous minified files -->
  <Exec Command="del $(ProjectDir)Styles\*-min.css" />
  <Exec Command="del $(ProjectDir)Scripts\*-min.js" />
  <!-- Minify javascript and css, unless we're in Debug -->
  <Exec Command="java -jar $(ProjectDir)..\yuicompressor\build\yuicompressor-2.4.6.jar -o .css$:-min.css --charset utf-8 $(ProjectDir)Styles\*.css" />
  <Exec Command="java -jar $(ProjectDir)..\yuicompressor\build\yuicompressor-2.4.6.jar -o .js$:-min.js --charset utf-8 $(ProjectDir)Scripts\*.js" />
</Target>

这将创建一个缩小的 * - min.js * - min.css 在〜文件\\脚本和〜\\样式,分别为。

This will create minified *-min.js and *-min.css files in ~\Scripts and ~\Styles, respectively.

警告的B /版本一个的bugÇ YUI的COM pressor的2.4.6 ,上面不会有如果只有一个正常工作的.css 。 JS 文件目录。

Warning B/c of a bug in version 2.4.6 of the yui compressor, the above won't work if there is only one .css or .js file in the directory.

这篇关于策略在Azure上的JavaScript文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆