简体   繁体   English

SquishIt框架支持Web场的Render方法中附加#

[英]Appending # in the Render method for SquishIt framework support web farm

I am using SquishIt framework to work on Bundling and Magnification feature for bundling and minifying the js and css files. 我正在使用SquishIt框架来处理捆绑和放大功能,以捆绑和缩小js和css文件。

I am using the code as mentioned below: 我正在使用下面提到的代码:

<%= Bundle.JavaScript()
        .Add("~/js/jquery-1.4.2.js")
        .Add("~/js/jquery-ui-1.8.1.js")
        .Render("~/js/combined_#.js")
%>

The above code works well in case I have a single webserver. 上面的代码在我只有一个Web服务器的情况下效果很好。 I want to know whether appending _#" in the output file name will create an issue in the webfarm. If it creates an issue then what is the best solution to resolve the issue. 我想知道是否在输出文件名中附加_#“会在webfarm中造成问题。如果产生问题,那么解决此问题的最佳解决方案是什么?

Can anyone help me to know more details about the occurrence of the issue in webfarm scenario. 谁能帮助我了解有关Webfarm场景中问题发生的更多详细信息。

Thanks & Regards, Santosh Kumar Patro 谢谢与问候,Santosh Kumar Patro

This can create issues if you don't have sticky sessions enabled in your load balancer. 如果未在负载均衡器中启用粘性会话,则可能会产生问题。 Because you are rendering the file in your view, it could be rendered on server 1 and the request for the asset actually ends up routed to server 2, where the file may not have been created yet. 由于您是在视图中渲染文件,因此可以在服务器1上渲染文件,并且对该资产的请求实际上最终路由到服务器2,在该服务器上可能尚未创建文件。

In a web farm scenario I think it is best to create your bundles on Application_Start, then render in your view using one of the cached / named methods. 在Web场方案中,我认为最好在Application_Start上创建捆绑包,然后使用缓存的/命名方法之一在视图中呈现。

So if you want to keep rendering to static files instead you'd have something like this in application_start (global.asax.cs) or downstream (I like a specialized initializer for SquishIt) 因此,如果要保留渲染到静态文件,则可以在application_start(global.asax.cs)或下游(我喜欢SquishIt的专用初始化程序)中使用类似的内容

Bundle.JavaScript()
    .Add("~/js/jquery-1.4.2.js")
    .Add("~/js/jquery-ui-1.8.1.js")
    .RenderNamed("bundleName", "~/js/combined_#.js") //2nd arg is used to resolve disk location

Then to render in your view: 然后在您的视图中渲染:

<%= Bundle.JavaScript().RenderNamed("bundleName") %>

This will ensure that the file has been created by the time the server is ready to respond to requests, at the expense of application startup time (make sure your app pool isn't getting recycled too often!). 这将确保在服务器准备好响应请求之前就已经创建了文件,而这会浪费应用程序的启动时间(请确保您的应用程序池不会被频繁回收!)。

The asset controller method may be better because it gives you a chance to recover if the bundle is not found. 资产控制器方法可能更好,因为如果找不到捆绑包,它可以让您有机会恢复。 You can read about that here: https://github.com/jetheredge/SquishIt/wiki/Using-SquishIt-programmatically-without-the-file-system 您可以在这里阅读有关内容: https : //github.com/jetheredge/SquishIt/wiki/Using-SquishIt-programmatically-without-the-file-system

Finally, using a CDN may be a good option as well. 最后,使用CDN可能也是一个不错的选择。 You can do some reading on that (using Amazon S3 / Cloudfront, but the ideas apply to any CDN) here: http://blogs.lessthandot.com/index.php/WebDev/ServerProgramming/making-squishit-work-with-amazon 您可以在此处进行一些阅读(使用Amazon S3 / Cloudfront,但是这些思想适用于任何CDN): http : //blogs.lessthandot.com/index.php/WebDev/ServerProgramming/making-squishit-work-with-亚马逊

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在SquishIt MVC框架中使用defer或webworker API? - How to use defer or webworker api with SquishIt MVC framework? 如何删除使用js和css文件中的更改创建的旧文件,而无需每次使用SquishIt框架手动清理它们 - How to delete the old files that are created with change in the js and css files without manually cleaning them everytime using SquishIt framework Web场中的ASP.NET MVC2-高流量导致页面加载缓慢 - ASP.NET MVC2 in the web farm - slow page load with high traffic 在扩展方法中渲染部分失败 - Render partial in an extension method fails 最新版本的SquishIt仍然存在JavaScript关闭问题吗 - Does the latest version of SquishIt still have the issues with JavaScript closures SquishIt是否在每个页面请求上都缩小并捆绑了CSS和JS文件? - Does SquishIt reminify and bundle the css and js files on every page request? System.Web.Mvc.IView.Render()的示例实现? - Sample Implementation for System.Web.Mvc.IView.Render()? 如何在通用方法中导航子Entity Framework对象? - How to navigate child Entity Framework objects in generic method? MVC Forms 身份验证 - 我如何处理服务器场上的托管? - MVC Forms Authentication - How do i handle hosting on a server farm? ASP.NET Web窗体渲染引擎输出控制树? 寻找渲染逻辑的信息 - ASP.NET Web Form Render Engine outputs a Control Tree? Looking for info on render logic
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM