我正在尋找使用Rejuicer http://rejuice.me/將我的ASP.net MVC站點的所有JS文件合併爲一個JS文件。這工作正常,但它不允許我添加或刪除JS文件,而不必重置/回收應用程序,因爲所有配置都在Application_Start()事件處理程序中設置。ASP.net Rejuicer動態合併js
有沒有人有任何想法我可以解決這個問題。或者如果Rejuicer有更好的選擇?
我正在尋找使用Rejuicer http://rejuice.me/將我的ASP.net MVC站點的所有JS文件合併爲一個JS文件。這工作正常,但它不允許我添加或刪除JS文件,而不必重置/回收應用程序,因爲所有配置都在Application_Start()事件處理程序中設置。ASP.net Rejuicer動態合併js
有沒有人有任何想法我可以解決這個問題。或者如果Rejuicer有更好的選擇?
在Application_Start中加載配置是一種折衷。其他選項是掛鉤到FileSystemWatcher並等待文件夾更改。鑑於Web應用程序的性質,這並不理想。一些替代使用web.config也強制重置。
有像Workbench這樣的工具,它在開發過程中(在VS.NET中)。這消除了對應用程序啓動週期的依賴,並且在應用程序啓動時存在文件。
在_layout.cshtml文件中我有類似於此的代碼。該網站的js文件列表可以在這裏定義,而無需重置或重新編譯該網站。
@{
//combine all JS files into one file using Rejuicer.
List<string> JsFiles = new List<string>();
//define list of JS files here
JsFiles.Add("~/Scripts/One.js");
JsFiles.Add("~/Scripts/Two.js");
if (System.Web.HttpContext.Current.Application["JsFileListing"] != null)
{
var JsFileRejuiced = (List<string>)System.Web.HttpContext.Current.Application["JsFileListing"];
//check if we have any new/removed/renamed files
if (JsFiles.Except(JsFileRejuiced).Count()> 0 || JsFileRejuiced.Except(JsFiles).Count() > 0)
{
//force application reset
HttpRuntime.UnloadAppDomain();
}
}
if (System.Web.HttpContext.Current.Application["JsFileListing"] == null)
{
var Combiner = Rejuicer.OnRequest.ForJs("~/Combined.js").Combine;
foreach (var file in JsFiles)
{
Combiner.File(file);
}
Combiner.Configure();
System.Web.HttpContext.Current.Application["JsFileListing"] = JsFiles;
}
}
@Rejuicer.Rejuiced.JsFor("~/Combined.js")
我曾想過web.config的想法,但我覺得有點奇怪在那裏列出js文件。 – MakkyNZ
不確定您是否收到關於此問題更新的通知,但我已添加可能的解決方案並想知道您的想法 – MakkyNZ
您上面的示例僅比較了文件數。將會介紹添加或刪除文件。但是特定js文件中的內容更改不會。你能解釋一下你重新設置應用的主要關注點嗎?通常情況下,這在生產和開發中並不常見,重置並不是什麼大問題。我個人更喜歡開發時間'榨汁'! – 2012-11-07 21:46:41