admin管理员组文章数量:1318156
I wonder what is the benefit and difference when using styles as Blob links:
<link rel="stylesheet" href="blob:">
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.
I wonder what is the benefit and difference when using styles as Blob links:
<link rel="stylesheet" href="blob:http://www.domain./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.
Share Improve this question edited Apr 17, 2016 at 18:34 juliancwirko asked Apr 17, 2016 at 14:51 juliancwirkojuliancwirko 1,28212 silver badges15 bronze badges2 Answers
Reset to default 7- Memory management
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/en-US/docs/Web/API/URL/createObjectURL#Notes
- Relative paths resolution
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.
Since Firefox doesn't yet support CSSStyleSheet
and adoptedStyleSheets
, your technique is very useful for creating self-contained web ponents prior to the ubiquity of Constructable Stylesheets. See the surrounding ments in this bug report.
本文标签: javascriptBlob based 39link stylesheet39 vs standard 39style39 tagStack Overflow
版权声明:本文标题:javascript - Blob based 'link stylesheet' vs standard 'style' tag - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742041313a2417559.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论