I wonder what is the benefit and difference when using styles as Blob links:
<link rel="stylesheet" href="blob:http://www.domain.com/hash-here">
over the standard tag:
<style>...</style>
I mean Blob creation like:
var blob = new Blob([css_here], {type: 'text/css'});
var link = document.createElement('link');
link.rel = 'stylesheet';
link.href = window.URL.createObjectURL(blob);
head.appendChild(link);
Thanks in advance.
What is blob url? Why it is used? Blob URL/Object URL is a pseudo protocol to allow Blob and File objects to be used as URL source for things like images, download links for binary data and so forth. For example, you can not hand an Image object raw byte-data as it would not know what to do with it.
The Blob object represents a blob, which is a file-like object of immutable, raw data; they can be read as text or binary data, or converted into a ReadableStream so its methods can be used for processing the data. Blobs can represent data that isn't necessarily in a JavaScript-native format.
Blob URLs contain pseudo protocols that can create a temporary URL to audio and video files. This type of URL essentially acts as a fake source for the media on the website, so you can't download it directly. Instead, you have to use third-party conversion tools.
If you put stuff as style
, and then remove - it's gone.
However, if you put stuff as blob url and then remove - you still have the blob url stored in memory, and it should be released manually.
See the notes here: https://developer.mozilla.org/en-US/docs/Web/API/URL/createObjectURL#Notes
With style
all relative urls inside are resolved transparently (e.g. @font-face { src: url('/assets/font.ttf'); }
.
But with blobs, those relative urls are treated as relative to the blob url itself (i.e. relative to blob:http://domain/some-hash
).
So the relative urls will effectively stop working in this case.
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