- From: Tab Atkins Jr. <jackalmage@gmail.com>
- Date: Fri, 15 Aug 2014 17:23:44 -0700
- To: www-style list <www-style@w3.org>
Relevant Chrome bug https://code.google.com/p/chromium/issues/detail?id=349978 Web Components have a problem currently, that both <link rel=stylesheet> and @import are defined to always import freshly; every use hits the network again (unless you have cache headers) and constructs fresh objects. If you're on your dev server and aren't sending cache headers, or are on an uncontrolled server that you can't adjust headers for, or are serving code from a Chrome App or similar where you can't tweak headers, this means that including any stylesheets in your component will produce a *ton* of network traffic for no good reason. Because of this, best practice is currently to either inline your styles in a <style>, or have your component setup code grab the styles via XHR and then create <style> elements with the retrieved text in each component. On a related note, Hixie is trying to integrate the various "import" mechanisms between HTML, CSS, and JS (on top of JS's module system), so you can retrieve things via `import` statements in JS, and they can all share a common dependency management system. He's also stymied by this behavior - he can't preload a stylesheet dependency and then actually use it when an @import appears, because it requires a fresh fetch and object. So, I'm trying to fix this. I think I can address both of these problems by making CSSRuleList constructable, and making it sharable across Stylesheet objects. When the UA is constructing them, it dedupes based on URL within the current top-level document, so all uses of a given URL share a single CSSRuleList object, though they generate different Stylesheet objects. This has an obvious possible compat issue - if people currently import the same url in multiple places and edit instances, expecting them to be separate, this will make any changes to one sheet affect every import. I suspect that's super-rare? Anyway, anyone have thoughts on this? I plan to go ahead and figure out how to make most of the CSSOM hierarchy constructable, since I might as well once I start in on this project. ~TJ
Received on Saturday, 16 August 2014 00:24:33 UTC