What is the "asp-fallback" in ASP.NET MVC, Razor Pages?

0

I see some files as lines similar to this:

<script src="https://ajax.aspnetcdn.com/ajax/jquery/jquery-2.2.0.min.js"asp-fallback-src="~/lib/jquery/dist/jquery.min.js"
        asp-fallback-test="window.jQuery"
        crossorigin="anonymous"
        integrity="sha384-K+ctZQ+LL8q6tP7I94W+qzQsfRV2a+AfHIi9k8z8l9ggpc8X+Ytst4yBo/hH+8Fk">
</script>

I searched and found it in English (read using the translator), and it looks like it calls the second file if the first one fails, but I do not know if that's the same or what the asp-fallback-test is or how they actually work .

    
asked by anonymous 01.03.2018 / 01:56

1 answer

1

When we are developing a web application one of the biggest concerns is the loading time of our application. One of the optimization techniques used is to use so-called CDNs for the most popular libraries.

If the user has already visited a site that uses the same file as that CDN you, this file is probably cached on his machine, which eliminates the need to download it again. This is good for the user who gains speed and for you that decreases the load on your server.

But what if the CDN is off the air? We need a second option to download this files. ASP.NET fallback helpers make it easier and more readable to do this.

  • asp-fallback-src is a second option for the src of an html element
  • asp-fallback-href is a second option for the src of an html element
  • asp-fallback-test is a check condition that we can perform to know whether fallback will be used or not.

Remembering that fallback helpers can be used to apply Polyfill techniques.

There are some fallback taghelpers options that you can find in official documentation

    
01.03.2018 / 13:07