![]() ![]() For example, the following image shows the timing details for loading the /Scripts/MyScripts/JavaScript6.js file. You can double-click on an asset to get detailed timing information. The blue bars show the time taken to receive the response data from the server. The yellow bar is the request time to first byte, that is, the time taken to send the request and receive the first response from the server. The gray bars show the time the request is queued by the browser waiting on the six connection limit. In the image below, the IE F12 developer tools network tabs shows the timing for assets required by the About view of a sample application. That means that while six requests are being processed, additional requests for assets on a host will be queued by the browser. Most of the current major browsers limit the number of simultaneous connections per each hostname to six. Bundling and minification improves load time by reducing the number of requests to the server and reducing the size of requested assets (such as CSS and JavaScript.) These PowerShell scripts can be invoked as a part of build in your CI and do the CSS and JS minification.Bundling and minification are two techniques you can use in ASP.NET 4.5 to improve request load time. $files = get-childitem $folder -recurse -force -include *.js $libPathCompressor = $PSScriptRoot "\lib\YuiCompressor\" $libPathEcma = $PSScriptRoot "\lib\YuiCompressor\" MINIFY JS FILE DOWNLOADYou ca download it with NuGet package or you can download it from download section on this article page. ::WriteAllText($file.FullName,$compressedContent)įor JavaScript files, the proses is pretty much the same except we need to create an instance of class and invoke Compress method of it.Īdditionally we also need to load assembly which is required for JavaScriptCompressor.Compress method. Set-ItemProperty $file.FullName -name IsReadOnly -value $false $compressedContent = $cssCompressor.Compress($content) $files = get-childitem $folder -recurse -force -include *.css $libPath = $PSScriptRoot "\lib\YuiCompressor\" The rest is just looping through all CSS fies in the folder and applying Compress method from loaded assembly. If you prefer not to use paths in PowerShell you can load the assemblies to GAC with gacutil and reference it with Add-Type cmdlet So first thing is to load the assembly in PowerShell with ::LoadFile. ![]() NET library and use it as if you are writing C# code. The nice past with PowerShell is that you can easily load any. ![]() It can be downloaded from the NuGet package page or download it from this article download section in the top right corner along with PoweShell scripts. It handles well both JS and CSS comments and removes all the whitespace without any issues so I decided to use it for PowerShell script as well. I used YUICompressor.NET library for minifying CSS and JS file on the runtime and did not find any issues with it. I had a similar case and that is when I used PowerShell script to minify CSS and JS files on the filesystem where web application was deployed. This is the case where you need automation to perform minification on the production file system which can be then taken to the CDN. However, the other side which is source control needs to keep the original files, so you cannot minify and check-in to your source control. The minification of CSS and JS can be easily one on the runtime with ASP.NET bundling which is build in in ASP.NET framework, but in case of distributing your resource files over CDN you cannot use the runtime minification. Minification of Cascade Style Sheet (CSS) and Java Script (JS) should be on a TODO list for every web application. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |