In MVC-4, bundles for compressing CSS & Js files can be linked in a layout file with this Razor syntax: @Scripts.Render("~/JavaScripts")
This generates a link in the layout file that includes a fingerprint, which is re-generated on each app-build, to assist with cache-control.
So the generated link looks like:
<script src="/JavaScripts?v=dSMc_JTHMMP5GrWnILSYt_QBMw-g1pPlzknSorXpkyQ1"></script>
I'd like to know how the fingerprint is being generated (to use for similar purposes), but Sytem.Web.Optimization is not yet open-source.
Bundling and minification are the performance optimization techniques that can help to improve load time by reducing the number of requests to the server and reducing the size of requested assets (such as JavaScript and CSS.)
Bundling is one of the features of MVC. By implementing this, we can improve performance request load time. Minification is the process of removing unnecessary data without changing its functionality such as removing white spaces, comments, converting the large variable names to small, etc.
Busting Browser's Cache by Bundling Thus, when a Web page requests a resource, it checks in cache first. If the resource is found in cache, use cached copy rather than retrieving the resources from the Server. Hence, whenever you change the content of CSS and JS, files will not reflect on the Browser.
Bundling and minification is enabled or disabled by setting the value of the debug attribute in the compilation Element in the Web. config file. In the following XML, debug is set to true so bundling and minification is disabled. To enable bundling and minification, set the debug value to "false".
The fingerprint is generated using a sha256 hash of the bytes from the bundle and then encoded:
byte[] hash = sha256.ComputeHash(Encoding.Unicode.GetBytes(bundle));
return HttpServerUtility.UrlTokenEncode(hash);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With