Buster Cache Strategy in ASP.Net

What is a good strategy for automatically applying and / or updating cache variables for a buffer on my javascript links and stylesheets on ASP.Net?

eg. Conversion

<script type="text/javascript" src="/js/myScript.js" /> 

to

 <script type="text/javascript" src="/js/myScript.js?rev=12345" /> 

UPDATE: Continuous integration is not required. I use continuous integration (especially for Jenkins), so it would be great if the variable update method was based, for example, on the build number.

Although I can live using the source variables manually in the source code and just update them using the strategy, it would be nice to add if the strategy could also apply the original variable if it does not exist (say, for legacy code).

At the top of my head, I can imagine using a Powershell script that scans all * .aspx and * .ascx files and uses a regular expression to search for relevant links and update them. But you know what they say about using regular expressions ... then I have two problems :)

+6
source share
2 answers

The answer to ASP.Net cache cache variables is to use one of the CSS / JS mini-library libraries .

I thought cache buffer variables should be updated every time we deploy them to our servers, but widget libraries use a hash tag based on the contents of individual CSS / JS files.

Since I am developing the .Net 3.5 website, my options have been a bit limited. I ended up using SquishIt (available as a NuGet package) and it was easy to integrate.

 <link href="/<my_css_path>/<css_file_1>.css" rel="stylesheet" type="text/css" /> <link href="/<my_css_path>/<css_file_2>.css" rel="stylesheet" type="text/css" /> <link href="/<my_css_path>/<css_file_3>.css" rel="stylesheet" type="text/css" /> 

has become

 <%= Bundle.Css() .Add("~/<my_css_path>") .Render("~/<my_css_path>/combined_#.css") %> 

and that’s basically it! A similar idea with javascript. As long as debug="true" in your web.config for local development and debug="false" for your intermediate / production environments, SquishIt will leave your CSS / JS unallocated and unminified for local development, and then combine, minimize and hash (for brute force) cache) for other environments.

+3
source

You can also look at Cassette, RequestReduce, and the Bundler.

Cassette : Automatically sorts, merges, minimizes, caches and versions all of your JavaScript, CoffeeScript, CSS, LESS, Sass, and HTML templates.

RequestReduce Makes Your Website Faster - Sometimes Much Faster - Almost Without Effort

  • Auto generates sprites from background images
  • Optimizes Sprite PNG format and compression
  • Minimizes CSS and Javascript
  • Optimizes caching headers and ETags
  • Works on any IIS website, including classic ASP and PHP
  • Can synchronize content on multiple web servers.
  • Works well with CDN
  • Compiles Less, Sass, and Coffee script

Bundler : "Compile, minimize, merge Less / Sass / Css / JS / CoffeeScript files. Easy to use from MVC"

+3
source

Source: https://habr.com/ru/post/914694/


All Articles