w3c / preload

Preload
https://w3c.github.io/preload/
Other
81 stars 31 forks source link

how to feature detect? #7

Closed getify closed 8 years ago

getify commented 9 years ago

How do I feature test if a new browser supports link rel=preload?

safareli commented 6 years ago

created separate issue "spec shuold mention that relList must also be implemented if preload is implemented" #126 or feel free to close that and reopen this one.

dalimian commented 4 years ago

here is a simpler version of @yoavweiss's snippet (https://gist.github.com/yoavweiss/8490dabb3e0aa112fc74) tailored just for this specific use case

  function preloadSupported() {
    var relList = document.createElement('link').relList;
    return !!(relList && relList.supports && relList.supports('preload'));
  }

given that there is no need for try/catch for this case (as he confirmed). Worked, and did not throw in any browser I tested with (IE 10+, safari 10.1+, chrome 50+, firefox 50+, edge 15+)