0

I've been learning about the various ways of content optimization for websites for months now, however I'm still confused about what's the right way of doing so e.g. which 'optimization workflow' results in what effects.

ASP.NET MVC provides its own optimization framework through the 'Microsoft.Web.Infrastructure' package. With that, I can define bundles and minification strategies directly in code on request or when the application starts. However, since my style files are written in less, I need to compile them beforehand, which might slow down the overall application start process, so I feel it might be better to compile those during the build process of the application. But then again, most stylesheet compilers allow to bundle and minimize directly, so why not doing anything there?

  1. LESS files should be compiled when the application compiles
  2. CSS files should be bundled to reduce the amount of needed client requests
  3. CSS files should be minimized to reduce traffic and overall page content size

So, what's the suggested way of accomplishing this?

  1. Compile LESS files on build (with e.g. dotless)
  2. Deploy application to server
  3. Bundle and minify on request using optimization bundles?

When does this bundling and minification happen in the ASP.NET lifecycle? On the first start of the web application? On every request?

Colin Bacon
  • 15,436
  • 7
  • 52
  • 72
Acrotygma
  • 2,531
  • 3
  • 27
  • 54

2 Answers2

0

Bundling and minification happens on application start.

By default the bundle is created on the first request and then cached on the server. The cached version is then used for all other requests.

Colin Bacon
  • 15,436
  • 7
  • 52
  • 72
0

The bundling and minification occur at the start of the web application. That is where we specify the process.

Some of the tools allow you to do it explicitly, in such cases we load the .min.js files directly. When we create a min.js using any tool, the source and minified files are different. These are mapped through a map file.

As we update the source files during development, there are chances that the min.js files are not updated when the source .js files are changed. This issue is more prominent when the files are source controlled. In such a scenario during deployments, it is common to find that the changes in the source machine aren't reflecting in the deployment.

The best thing for bundling and minification would be to adopt the Optimization framework provided by ASP .NET, this does the job dynamically unlike other external tools.

When compilation debug = true it skips the process and loads the original files without bundling, when it is false, the framework bundles all the specified JS and CSS files and deploys it to the server.

I hope this answers your question.