I like the Template element, but what I'd really like is a way to escape out of JavaScript and html directly to my JavaScript views. That'd be more convenient than splitting client side view development across the JavaScript logic and html templates that reside somewhere else.
Plus, I think that'd offer caching benefits vs. having to send templates across the wire every time.
I keep most of my templates in separate .htm files and load them via XHR for a handful of reasons, including caching as you mentioned. Works great.
It would be nice if the new template element had built-in support for that (e.g. a src attribute and maybe some sort of control for loading immediately, after document ready, and/or on demand).
Awesome indeed, the thing that always makes me sad though is that you'll always have that IE 8 user which can't see your website properly, sure, you can use Javascript to make up for it, but it kills the whole emotion of using something awesome.
Why does it kill the emotion? With yepnope (and other libs) you can do conditional loading and only use the JS shims on IE8 while the other always-green browsers use the awesome stuff.
I know, and it's awesome but I'd like to just say "Cool! Now I can use this awesome technology and forget about the 100 JS alternatives for doing the same thing", but I still cannot forget about those ;(
Not to mention the controversial Encrypted Media Extensions. I'm curious to see who the first to use them will be, and how easy the implementation will be to break.
> The element allows you to store HTML fragments that you intend to use for any reason at any time during the lifetime of your page, but that aren’t ready or shouldn’t be used during page load.
It's faster because it's not interpreted until it's actually being used. Think of all these mustache templates or display: none elements that are not needed on page load.
Not just to make the markup pretty. It also means that if you view the page without scripting, or with a screen reader, you'll get results that make sense. And it means that robots, scrapers, indexers, and search engines can actually see the template content, which they can't easily do if you embed it in Javascript document.createElement calls.
Webkit/Chromium/Chrome's project development process is interesting. From what I've seen on the bug trackers, whenever a piece of code (no matter what size) causes any sort of stability/performance regression at all, the patches committing it are aggressively backed out and dropped on the floor, with the expectation that whoever cared enough to commit them in the first place will realize their code was pulled, fix it, and re-commit.
This causes features to sometimes just "go missing" for long periods of time, if the original committer (i.e. the code's only advocate with commit privs) A. works for some big company that's not Google or Apple, and thus has other responsibilities; B. was just "helpfully" pushing the code they wrote for their own private fork of Webkit/Chromium; and C. doesn't much care what happens to it in the OSS project after that.
- any feature, no matter how small, has some cost (code size, testing, cognitive complexity, etc), and frequently contributes in some way to making the product and/or other development slower.
- as a developer, user, product manager etc, it's up to you to figure out how to convince other people your change is a good idea, and how your change will be maintained going forward, if you have to switch projects for instance.
We have a long history on the Chrome team of deleting code that was only relevant to one or two developers and those developers moved onto something else. It's the only way to stay sane at our scale, frankly, and we don't even do it as much as we should.
It probably is a good idea to get the code "out of sight", yes, but "deleting the code from the repo altogether" still seems a bit odd to me.
I guess I'm too used to DCVSes with light feature branching--I would expect every piece of code to end up in your codebase as a result of a merge commit, and be backed out by backing out that merge commit--leaving the unmerged feature branch itself available indefinitely if anyone ever does want to take up the reins on that particular idea again. As it is, it feels a bit like a publisher shredding every manuscript that contains a typo ;)
---
Oh! And since I have a Chrome developer on the line, so to speak: when are we going to see nearest-neighbour image-scaling (https://bugs.webkit.org/show_bug.cgi?id=56627) in Chrome for Windows/Linux? As it is, I get an itch whenever I see pixel-art emoticons with CSS- or device-zoom applied to them. :)
I used to have an issue on linux (ubuntu and mint-debian) where chrome and chromium would freeze the entire computer if left running long enough. I never did find a solution for that.
Templates look nice, but I really wonder how different this technique is from document fragments that one can create using document.createDocumentFragment and other related DOM handling through the convenient JS API.
What's the performance on <template>? This approach seems like it'd be slower than having templates precompiled on the server and already served as JavaScript.
I assume the only overhead will be how much they weight in your DOM (this is inevitable anyway) and whatever time it takes to clone the element. So probably it will be actually faster than compiling server-side and XHR-ing on-demand because you don't touch the network.
36 comments
[ 3.3 ms ] story [ 76.1 ms ] threadPlus, I think that'd offer caching benefits vs. having to send templates across the wire every time.
It would be nice if the new template element had built-in support for that (e.g. a src attribute and maybe some sort of control for loading immediately, after document ready, and/or on demand).
> The element allows you to store HTML fragments that you intend to use for any reason at any time during the lifetime of your page, but that aren’t ready or shouldn’t be used during page load.
It's faster because it's not interpreted until it's actually being used. Think of all these mustache templates or display: none elements that are not needed on page load.
CSS calc() unprefixed on Chrome 26+
This causes features to sometimes just "go missing" for long periods of time, if the original committer (i.e. the code's only advocate with commit privs) A. works for some big company that's not Google or Apple, and thus has other responsibilities; B. was just "helpfully" pushing the code they wrote for their own private fork of Webkit/Chromium; and C. doesn't much care what happens to it in the OSS project after that.
- any feature, no matter how small, has some cost (code size, testing, cognitive complexity, etc), and frequently contributes in some way to making the product and/or other development slower. - as a developer, user, product manager etc, it's up to you to figure out how to convince other people your change is a good idea, and how your change will be maintained going forward, if you have to switch projects for instance.
We have a long history on the Chrome team of deleting code that was only relevant to one or two developers and those developers moved onto something else. It's the only way to stay sane at our scale, frankly, and we don't even do it as much as we should.
I guess I'm too used to DCVSes with light feature branching--I would expect every piece of code to end up in your codebase as a result of a merge commit, and be backed out by backing out that merge commit--leaving the unmerged feature branch itself available indefinitely if anyone ever does want to take up the reins on that particular idea again. As it is, it feels a bit like a publisher shredding every manuscript that contains a typo ;)
---
Oh! And since I have a Chrome developer on the line, so to speak: when are we going to see nearest-neighbour image-scaling (https://bugs.webkit.org/show_bug.cgi?id=56627) in Chrome for Windows/Linux? As it is, I get an itch whenever I see pixel-art emoticons with CSS- or device-zoom applied to them. :)
EDIT: chrome has flash on linux, last i checked. are you using your package manager's version of chromium?
I found a fix shortly after I posted this comment.
They fixed in v24 (but mine isn't upgrading automatically, even after restart from v22). So instead, I followed this:
http://productforums.google.com/d/msg/chrome/PEgELQH5zcg/c5l...
I honestly used to go weeks or longer without any crashes.