ebidel
Turning on certain policies can also help you be certain quality/standards are being met across your site. For example, the creative team forgets to optimize images and you end up shipping many more MBs of images than actually needed. The `image-compression` feature policy could be used as a gut check to make sure that never happens.
https://github.com/GoogleChrome/puppeteer/issues/306#issueco...
See
- https://bugs.chromium.org/p/chromium/issues/detail?id=546953...
- https://bugs.chromium.org/p/chromium/issues/detail?id=695212
What developers often do is pull in a ton of components from the web components catalog and not realize that every component comes with a cost. It's no different than working with libraries. Know the tradeoffs.
There are plenty of examples of fast rendering apps that written with Polymer. Check out https://shop.polymer-project.org/ and https://www.chromestatus.com/features, to name two.
https://ebidel.github.io/polymer-experiments/polymersummit/f... is another example that shows how to utilize the "upgrade" feature [1] of the custom elements API. IOW, the browser can render markup without JS ever running. Unfortunately, this is not something that Polymer leverages very much. It requires more work and is less friendly to new developers.
[1]: https://developers.google.com/web/fundamentals/getting-start...
The Chrome team is hashing out potential solutions to the server push <-> browser cache problem.
With React, you have to use inline styles (https://facebook.github.io/react/tips/inline-styles.html) or a build tool to modularize/prefix CSS selectors (e.g. CSS Modules). Inline styles can muck with specificity and tons of inline styles can actually force the browser to do more context switching than necessary (HTML parser <-> CSS parser). Mind you, the latter is unlikely to actually be a perf issue in a real app.
In shadow dom, you just write CSS. Write simple selectors in a `<style>` or a stylesheet, the browser automagically scopes the selectors to the component, no tools required. Shadow roots also prevent outer styles from cross the boundary and leaking in. That one is particularly tricky without help from the browser.
As for perf...
In theory, the browser can optimize work (style recalcs, layout, paint) in shadow trees b/c the DOM is local.
However, generally there's a lot of low hanging fruit still to look at. Browser engines have been optimized for global css so those paths are super fast right now. https://bugs.chromium.org/p/chromium/issues/detail?id=314303 is a good example of the work that can be done (now fixed in Blink):
> Being inside a ShadowRoot disables lots of optimizations we have for the normal document. Authors also use ShadowRoots differently than the main document (ex. hundreds of tiny identical sheets in each Shadow instead of one really big one in the document) so we should consider those use cases and how we can handle them better.
> We should be able to get much faster. This bug tracks the many efforts to make recalcStyle faster in ShadowRoot (and by extension Web Components)
Another thing Blink does is optimize `<style>`s so they're shared/cached across instances of a component (as long as their `.textContent` is the same). That was a pretty big speed up in Blink.
Shadow DOM v1: self-contained web components
Obviously doesn't include stuff in the works :)
Re. "bloat" of components. I think it's important to remember everything something like paper-input is doing for _you_. As a developer, I no longer have to think about: validation, animations, a11y, keyboard, knowing all the MD spec configurations, labels, underlines, colors, fonts, typography, margins, composability, x-browser interop,... Sure, if you were implementing your own input, you could cut corners and/or leave out what you didn't need. However, if you were creating a highly reusable, highly configurable element, you'd be implementing the same amount of "bloat" yourself.
FWIW, Chrome has a bug where SW doesn't intercept URLs changed using history.pushState(). If you're using the web app in Chrome 40, turning off wifi and navigating the site will show "blank pages". However, refreshing the page you land on does will work as expected while offline.
Good news is that it has been fixed in Chrome 41...coming soon! https://code.google.com/p/chromium/issues/detail?id=429972
It's 100% bizarre to think about elements that don't render UI. Honestly, I'm still wrapping my head around it.
If you think about it though, there are plenty examples today that don't render UI (directly) but serve a specific purpose: <script>, <meta>, <html>, <style>, <head>, <title>, <link>, ....
Search for "display: none": http://src.chromium.org/viewvc/blink/trunk/Source/core/css/h...
Interesting times indeed.
> What really remains to be seen is whether this reduces or increases complexity.
One word: scoping
This is an important concept in software development that we've severely lacked on the web. We're used to creating global documents of HTML, CSS, and JS and hoping it doesn't explode. Frankly it's a mess. I'm surprised we've put up with it for so long! The technologies behind web components (Shadow DOM and Custom elements in particular) empower us web devs to be good developers. That is, we can take advantage of patterns like OOP: compartmentalize and scope functionality to a particular problem space.
CSS/DOM encapsulation is an added benefit to tell this story. As a developer, I no longer have to hunt down what CSS is effecting my page. I just look at the element's definition.
The hope with all of this stuff is that there's less re-inventing the wheel and more productivity. Scoping takes us to this happy place. Unlike most new web platform APIs, the web component APIs are purely about developer ergonomics. It's about your productivity. That makes me super happy...both as a web dev and someone who teaches web devs.
> Like Addy points out ("not a silver bullet") performance, security,...
Nothing in web development is a silver bullet :) A best practice today may be an anti-pattern tomorrow. However, with components, we have the opportunity to bake in more for free. For example, accessibility is low on people's radar. If a component set takes care of the details for me, I'm a happy camper.
Nothing changes in regards to security. In fact, the API specs leave it out entirely. When people hear "encapsulation", they automatically think security. IMO, it's better to think about components as "scopes".
> ...one of Polymer's example components was an Ajax call, which I suppose you can fire from the script. Is that really better than putting the ajax parameters in the code?
Web components allow us to rethink what HTML can be; what it can do. We have to unlearn years (possibly) decades of assuming that HTML can provide no useful API. When given a declarative vs imperative API, I suspect 9/10 developers will go the declarative route. It's unquestionably easier.
`<polymer-ajax>` is a good example of providing an a hybrid. It defines an imperative API on its DOM interface and a declarative one by configuring it through attributes and listening for events. Is the declarative route better? Perhaps. The point is that it encapsulates the details of using XHR. I'm excited to never NEVER write that boilerplate XHR code again.
Ajax is also a trivial example. The cognitive load of being a web developer is oftentimes too high. You can imagine more complex APIs and libraries (webrtc, webgl, etc) being offered as declarative custom elements. A declarative option makes those underlying technologies more convenient/approachable to others.
> Does it encourage "globals"-like behavior, where hidden dependencies crop up?
Components encourage the opposite. When used correctly, HTML Imports provides the necessary dependency management. If an element requires script x and element y, those deps can be included/bundled as an Import for the component.
> Are there life-cycle behaviors to the Ajax component that might trigger the request at surprising or frustrating times?
There's nothing stopping component authors from shooting themselves (or their users) in the foot. It's my hope that well-written components will surface to the top of the stack. If a component is naughty, no one will use it.
Polymer's entire stack is a la carte:
* platform.js - polyfills if you just want to use vanilla web component apis, today
* polymer.js - build declarative custom elements that use data-binding, touch, property observation, inheritance
* elements (ui/non-ui) - if you don't want to write any code at all :)
Sugaring libraries like Brick and Polymer that sit on top of the native web component APIs will, of course, be opinionated and do things a bit differently. However, the workflow for consuming components will be similar across the board. Something like `bower install brick-carousel polymer-tabs`. Then use the elements in your pages.
An analogy can be made to requestAnimation. raF isn't required to create animations, but it's highly useful in that context. raF can also be used for other use cases outside of animations (scroll effects, etc). Shadow DOM is the same IMO. It's a useful standalone technology, but when used in the context of web components, it really shines.
[1]: http://w3c.github.io/webcomponents/spec/custom/ [2]: http://w3c.github.io/webcomponents/spec/shadow/
[1]: http://stackoverflow.com/questions/18089075/what-is-the-diff...
That said, one goal is to have a continuous feedback loop with standards bodies to get things spec'd out if it makes sense to add them to the web platform. Similar to how querySelector landed after jQuery made it "a thing".
> <input value="{{firstName}} {{lastName}}">
This will work as you expect (http://jsbin.com/ecejiy/6/edit). Plus, if either of those property values change, the input.value will be updated accordingly.
By the way, you can also add/define your own syntax for MDV bindings: https://github.com/Polymer/mdv/blob/master/docs/syntax.md