asp.net-optimization

ASP.NET Optimization - Bundling

蓝咒 提交于 2019-11-30 05:02:40
I've been trying out the new minification and bundling feature in ASP.NET MVC 4, and it works great as long as you use the default folder conventions for css and js files. /Content /Scripts I usually put css and script in a folder called Static like this /Static/Css /Static/Js I tried to register my own bundles like this: public static class BundleCollectionExtensions { public static void RegisterScriptsAndCss(this BundleCollection bundles) { var bootstrapCss = new Bundle("~/Static/Css", new CssMinify()); bootstrapCss.AddDirectory("~/Static/Css", "*.css"); bootstrapCss.AddFile("~/Static/Css

MVC4 bundling/minification with IE conditional comments

时光总嘲笑我的痴心妄想 提交于 2019-11-30 05:00:55
I am trying to use MVC4's new "bundling and minification". For IE conditional comments, I'm still doing it the old way: <!--[if lt IE 9]><link href=.../><![endif]--> or <!--[if lt IE 9]>@Styles.Render("~/foo")<![endif]--> but I don't seem to get the automatic debug/release handling. Is there a built-in way to do this? How are others doing this? EDIT: Also it would be great to be able to include <noscript> tags inside the rendered output (used for fallbacks). Until I find a better way, I made an adaptor class called Bundles , which has the method: public static IHtmlString RenderStylesIe(string

Bundling .js files vs CDN

雨燕双飞 提交于 2019-11-29 22:06:35
In order to improve performance of our web pages, we are recommended to use CDN s to serve .js files on our web pages. That makes sense. Also, we are recommended to bundle our .js files in order to reduce the number of requests which are being made to server on load. So, we need to sit down and make decision between if we use CDN or bundle .js files. What are the pros and cons? Which ones make more sense? Matt Why can't you bundle them and place them are the CDN? It should hardly be a decision of one or the other? If you have to choose one or the other, it depends on how many .js files you are

Is it possible to unit test BundleConfig in MVC4?

£可爱£侵袭症+ 提交于 2019-11-29 13:38:49
As far as I can tell, the answer is no. The issue I'm seeing comes from the Include(params string[]) method in the System.Web.Optimization.Bundle class. Internally this invokes System.Web.Optimization.IncludeDirectory(string, string, bool) , which in turn uses this code: DirectoryInfo directoryInfo = new DirectoryInfo( HttpContext.Current.Server.MapPath(directoryVirtualPath)); While it is possible to set HttpContext.Current during a unit test, I can't figure out how to make its .Server.MapPath(string directoryVirtualPath) return a non-null string. Since the DirectoryInfo(string) constructor

MVC4 Bundle minification doesn't work with javascript reserved words

痞子三分冷 提交于 2019-11-29 12:16:58
问题 Using the latest version of MVC4 I can't minify javascript when it contains reserved words as key names! See the error below with the valid javascript that should have been minified. Does anyone know how to fix this short of rewriting the javascript to use [""] notation? PS The code in question is a few thousand lines long, so it's not an option! /* Minification failed. Returning unminified contents. (3,9-15): run-time warning JS1010: Expected identifier: delete (4,9-13): run-time warning

ASP.NET Optimization - Bundling

泄露秘密 提交于 2019-11-29 02:47:49
问题 I've been trying out the new minification and bundling feature in ASP.NET MVC 4, and it works great as long as you use the default folder conventions for css and js files. /Content /Scripts I usually put css and script in a folder called Static like this /Static/Css /Static/Js I tried to register my own bundles like this: public static class BundleCollectionExtensions { public static void RegisterScriptsAndCss(this BundleCollection bundles) { var bootstrapCss = new Bundle("~/Static/Css", new

MVC4 bundling/minification with IE conditional comments

僤鯓⒐⒋嵵緔 提交于 2019-11-29 02:41:16
问题 I am trying to use MVC4's new "bundling and minification". For IE conditional comments, I'm still doing it the old way: <!--[if lt IE 9]><link href=.../><![endif]--> or <!--[if lt IE 9]>@Styles.Render("~/foo")<![endif]--> but I don't seem to get the automatic debug/release handling. Is there a built-in way to do this? How are others doing this? EDIT: Also it would be great to be able to include <noscript> tags inside the rendered output (used for fallbacks). 回答1: Until I find a better way, I

Why does ResolveBundleUrl not work for custom folders? (MVC Beta 4)

梦想的初衷 提交于 2019-11-29 01:15:57
From a brand-new ASP.NET MVC 4 Beta Web Application, I'm re-arranging my folders to match Rob Conery's VidPub.Web example Specifically, this means that the final directory structure for content looks like this VidPub.Web | ---Public | |---Images |--- *.png |---javascripts |--- *.js |---stylesheets |----themes |---base |--- images |--- *.css |----site.css However, when I change the following lines in _Layout.cshtml <link href="@System.Web.Optimization.BundleTable.Bundles.ResolveBundleUrl( "~/Content/css")" rel="stylesheet" type="text/css" /> <link href="@System.Web.Optimization.BundleTable

Bundling .js files vs CDN

雨燕双飞 提交于 2019-11-28 18:23:27
问题 In order to improve performance of our web pages, we are recommended to use CDNs to serve .js files on our web pages. That makes sense. Also, we are recommended to bundle our .js files in order to reduce the number of requests which are being made to server on load. So, we need to sit down and make decision between if we use CDN or bundle .js files. What are the pros and cons? Which ones make more sense? 回答1: Why can't you bundle them and place them are the CDN? It should hardly be a decision

MVC4 Less Bundle @import Directory

天涯浪子 提交于 2019-11-28 15:58:06
I'm trying to use MVC4 bundling to group some of my less files, but it looks like the import path I'm using is off. My directory structure is: static/ less/ mixins.less admin/ user.less In user.less, I'm attempting to import mixins.less using this: @import "../mixins.less"; This used to work for me before when using chirpy with dotless, but now I noticed ELMAH was getting mad at me, saying this: System.IO.FileNotFoundException: You are importing a file ending in .less that cannot be found. File name: '../mixins.less' Am I supposed to use a different @import with MVC4? Some additional info Here