简体   繁体   English

缓存静态内容以提高IIS的页面性能

[英]Cache static content for speed up Pages performance IIS

My application is in mvc4. 我的应用程序在mvc4中。 When I render page its take too much time. 当我渲染页面时,它花费了太多时间。 I've checked in network tab its taking too much time for rendering .js files. 我已经检查了“网络”选项卡,它花费太多时间来呈现.js文件。

Can any one guide me how to do cache for static folder in iis 8.5 or any thing i can do in web.config after that i increase performance of my website and their pages. 任何人都可以指导我如何在iis 8.5中为静态文件夹进行缓存,或者在我提高网站及其页面的性能之后在web.config中可以执行的任何操作。


It's taking time 10-20 seconds to render page. 呈现页面需要10到20秒的时间。 Here is the image of time. 这是时间的图像。

All js files are in script folder, is their any method to cache whole folder? 所有js文件都位于脚本文件夹中,它们是否有任何方法可以缓存整个文件夹? 在此处输入图片说明

You can improve request load time using bundling. 您可以使用捆绑服务缩短请求加载时间。

Add your bundle class to App_Start folder, and all Js file like following. 将您的捆绑软件类添加到App_Start文件夹,然后将所有Js文件添加如下。

 public class BundleConfig
    {
        public static void RegisterBundles(BundleCollection bundles)
        {

            bundles.Add(new StyleBundle("~/Content/trans/css").Include(
              "~/Content/bootstrap_min.css",
              "~/Content/Theme/Css/style.css",
            ));
            bundles.Add(new JsBundle("~/Content/themes/base/css").Include(
                    "~/Content/themes/base/jquery.ui.core.js",
                    "~/Content/themes/base/jquery.ui.resizable.js",
                    "~/Content/themes/base/jquery.ui.selectable.js",
                    "~/Content/themes/base/jquery.ui.accordion.js",
                    "~/Content/themes/base/jquery.ui.autocomplete.js",
                    "~/Content/themes/base/jquery.ui.button.js",
                    "~/Content/themes/base/jquery.ui.dialog.js",
                    "~/Content/themes/base/jquery.ui.slider.js",
                    "~/Content/themes/base/jquery.ui.tabs.js",
                    "~/Content/themes/base/jquery.ui.datepicker.js",
                    "~/Content/themes/base/jquery.ui.progressbar.js",
                    "~/Content/themes/base/jquery.ui.theme.js"));
    }

   }
} 

Register your bundle to Global.asax file. 将您的捆绑包注册到Global.asax文件。

BundleConfig.RegisterBundles(BundleTable.Bundles);

And use that js bundle on view page( _Layout.cshtml ) 并在视图页面上使用该js捆绑包( _Layout.cshtml

@Scripts.Render("~/bundles/JsBundle")

Same way you can also bundle CSS files. 同样,您也可以捆绑CSS文件。

Hope this will help you! 希望这个能对您有所帮助!

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM