Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should I be appending asp-append-version="true" to all my images in asp.net MVC6?

The question is in the title. It seems logical to use this tag helper for every image but if I am indeed supposed to why wasn't this the default?

Is there any performance hit with this? Are there cases when I shouldn't be decorating an image with this tag helper?

like image 930
Cool Breeze Avatar asked Jan 20 '16 03:01

Cool Breeze


People also ask

How does ASP append version work?

If you add asp-append-version="true" attribute to <script> or <style> tag Asp.net core will auto add version to end of URL path. This version always unique and change after each deploying a new code version. It always creates a new URL to help browser auto clear cache for this file and always update the latest code.

What is the difference between tag helper vs HTML helper?

Tag Helpers are attached to HTML elements inside your Razor views and can help you write markup that is both cleaner and easier to read than the traditional HTML Helpers. HTML Helpers, on the other hand, are invoked as methods that are mixed with HTML inside your Razor views.

What is ASP Net mvc6?

ASP.NET MVC is a web application framework developed by Microsoft that implements the model–view–controller (MVC) pattern. It is no longer in active development. It is open-source software, apart from the ASP.NET Web Forms component, which is proprietary.

What are Taghelpers?

Tag helpers are a new feature and similar to HTML helpers, which help us render HTML. There are many built-in Tag Helpers for common tasks, such as creating forms, links, loading assets etc. Tag Helpers are authored in C#, and they target HTML elements based on the element name, the attribute name, or the parent tag.


1 Answers

The main use of asp-append-version=true is to bypass the browser cache if the content item has changed. It is very useful for javascript that is likely to change.

Images don't get updated very often unless you have an unusual use case. If you have a use case where images do get updated and they keep the same file name then it would make sense to use it there but otherwise it would not.

I can't say how much performance hit would be involved, but it does create a hash of the file content to use for the version string that is appended. There is some impact for any extra code that is executed when it is not needed. It does not make sense for it to be a default behavior, it should be used by opting in to it if you really need it.

like image 54
Joe Audette Avatar answered Oct 21 '22 11:10

Joe Audette