I'm trying to preload a video using the link
tag's preload rel value per mdn's documentation on preload.
in my index.html file I'm adding the following to the head:
<link rel="preload" as="video" type="video/mp4" href="video/2_1.mp4" />
In chrome this works fine and preloads the file without issue.
When I open the page in safari 11.3 either on my desktop or on an iphone I get a console error message:
must have a valid
as
value
According to the "what types of content can be preloaded" section of the documentation that contains the list of valid values I'm definitely using the correct video
type.
I checked both the mdn documentation for mobile safari preload option on the link tag and it shows a "compatibility unknown" question mark. I also checkedcaniuse and it seems to indicate that as long as my mobile safari version is at 11.3 I should be able to use it.
The phone and my desktop are both at safari 11.3, so I'm not sure why I'm getting this error.
Any ideas/insight??
The preload value of the <link> element's rel attribute lets you declare fetch requests in the HTML's <head> , specifying resources that your page will need very soon, which you want to start loading early in the page lifecycle, before browsers' main rendering machinery kicks in.
The preload attribute specifies if and how the author thinks that the media file should be loaded when the page loads. The preload attribute allows the author to provide a hint to the browser about what he/she thinks will lead to the best user experience.
The rel="preload" attribute value is used to preload assets. It can be applied to several file formats, including CSS, JS, fonts, images, and more. Depending on the type of file you would like to preload, the corresponding as attribute may also need to be included along with rel="preload" .
preload is a declarative fetch, allowing you to force the browser to make a request for a resource without blocking the document's onload event. Prefetch is a hint to the browser that a resource might be needed, but delegates deciding whether and when loading it is a good idea or not to the browser.
it seems webkit disable preload for video and audio file.
if (RuntimeEnabledFeatures::sharedFeatures().mediaPreloadingEnabled() && (equalLettersIgnoringASCIICase(as, "video") || equalLettersIgnoringASCIICase(as, "audio")))
return CachedResource::MediaResource;
if (equalLettersIgnoringASCIICase(as, "font"))
return CachedResource::FontResource;
#if ENABLE(VIDEO_TRACK)
if (equalLettersIgnoringASCIICase(as, "track"))
return CachedResource::TextTrackResource;
#endif
return std::nullopt;
https://github.com/WebKit/webkit/blob/master/Source/WebCore/loader/LinkLoader.cpp#L125
auto type = LinkLoader::resourceTypeFromAsAttribute(as);
if (!type) {
document.addConsoleMessage(MessageSource::Other, MessageLevel::Error, String("<link rel=preload> must have a valid `as` value"));
return nullptr;
}
https://github.com/WebKit/webkit/blob/master/Source/WebCore/loader/LinkLoader.cpp#L239-L243
I'm not sure if we can enable mediaPreloadingEnabled on safari by changing some configuration.
as="video|audio|document"
isn't supported on Chrome.Didn't found any official post/bug on the browsers sites, but I did found this on chromium repository: https://github.com/chromium/chromium/blob/99314be8152e688bafbbf9a615536bdbb289ea87/third_party/blink/web_tests/fast/dom/HTMLLinkElement/link-preload-unsupported-destination.html
<link rel=preload href="resources/empty.html"> <link rel=preload href="resources/empty.html" as="document"> <link rel=preload href="../../../media/content/test.mp4" as="audio"> <link rel=preload href="../../../media/content/test.wav" as="video"> <!--This test verifies that specific warnings are shown when preload resources use unsupported (but valid) destinations. -->
Basically it's a test that verify that Chrome throws a warning when using those link unsupported 'as' attributes
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