Answered by:
asp-fallback-test for loading leaflet.js

Question
-
User-158191824 posted
I need to complete using leaflet.js in asp-callback tag helper:
asp-fallback-test=" ? ? ? "
By this time, I haven't found a doc, to find out how to use it for any other .js file, as you know lots of .js files are on CDN servers, there should be a general rule for writing the code...
Tuesday, December 8, 2020 6:50 AM
Answers
-
User-474980206 posted
It is any JavaScript expression that returns true if the the library is loaded. Be sure it doesn’t throw an error if not loaded. The typical test is window.<some global from the library>
https://docs.microsoft.com/en-us/aspnet/core/mvc/views/tag-helpers/built-in/script-tag-helper?view=aspnetcore-5.0
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Tuesday, December 8, 2020 3:36 PM
All replies
-
User-474980206 posted
It is any JavaScript expression that returns true if the the library is loaded. Be sure it doesn’t throw an error if not loaded. The typical test is window.<some global from the library>
https://docs.microsoft.com/en-us/aspnet/core/mvc/views/tag-helpers/built-in/script-tag-helper?view=aspnetcore-5.0
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Tuesday, December 8, 2020 3:36 PM -
User-158191824 posted
Thanks a lot for answering . I've seen the reference before but nothing about what you said : The typical test is window.<some global from the library>
I solved my case by using asp-fallback-test="window.L" , and I saw the leaflet codes, many places used L.Somthing !! So I used L as global and it worked. but if you would mind getting more explanation about global, I searched Leaflet.js but all the variable are inside function(t,i), I looked at Leaflet Docs it is using L every where...
the other point, always we have 404 error on not loading first resource... I hope you meant "not throwing error" is any error except 404
Tuesday, December 8, 2020 4:26 PM -
User-474980206 posted
leaflet.js is built as a javascript module, so normally you'd supply the name when importing. but the build exports leaflet a global defined as L
https://github.com/Leaflet/Leaflet/blob/master/package.json
https://github.com/Leaflet/Leaflet/blob/master/build/rollup-config.js
Tuesday, December 8, 2020 5:11 PM