performance on the web 2. ParallelJS: parallelized JavaScript code 3. ECMAScript 6: evolving the language, uniting the community 4. CSS Grid Layout: native-like GUI layout 5. Installable web apps: install web apps natively 6. Web Components: a standard infrastructure for widgets 2
Boxing: type-tagged values must be extracted • Enables primitives and objects to coexist • JIT compilation (slow version first, fast version later) • Runtime type checks • Garbage collection • Flexible data structures 4
and limited subset of JavaScript. • Can be compiled ahead of time, to fast code. • Foundation: JavaScript’s semantics and compiler infrastructure. • Easier to standardize • Easier to implement 5
foreign, heap) { "use asm"; // mark as asm.js module ! function func1(...) { ... } function func2(...) { ... } ... ! return { exportedFunc: func1, ... }; } Normal JavaScript function, obeying certain rules. • stdlib: access to standard library (esp. Math) • foreign: foreign function interface, access to normal JS code. • heap: instance of ArrayBuffer 6
to fast code: function DiagModule(stdlib) { "use asm"; var sqrt = stdlib.Math.sqrt; function square(x) { x = +x; return +(x*x); } function diag(x, y) { x = +x; y = +y; return +sqrt(square(x) + square(y)); } return { diag: diag }; } // Link and use: var fast = DiagModule(window); // link module console.log(fast.diag(3, 4)); // 5 7
0; // int var b = 0.0; // double Parameters and return values: function func(x, y) { x = x|0; // int y = +y; // double return +(x * y); // returns double } 8
low-level: asm.js • Rarely hand-written (use C++, other LLVM languages, LLJS) • Pragmatic alternative to bytecode (similar, with pros + cons) • Slow, high-level: JavaScript JavaScript source code:! • Universal format for delivering code on the web • Abstracts over • Compilation strategies of various engines • High level vs. low level 11
• Array.prototype.filterPar() • Array.prototype.reducePar() • Similar to traditional array methods map(), filter(), reduce() • Order in which elements are processed is undefined. 㱺 can be parallelized 15
parallelism for JavaScript • Limited, but safe (no locks, no concurrent write access to data) • Tentatively scheduled for ECMAScript 8 (ca. end of 2018) • Probably in engines long before 19
JavaScript (current: ECMAScript 5.1) • Cleans up and evolves the language • Standardized by June 2015 • Can already be used today, via cross-compilation: • TypeScript • Next versions of: Ember.js, AngularJS • etc. 21
with native GUI layout (Android, iOS, Java SWT, …) • Better than: • Flexbox (only one dimension) • Tables (not enough control over sizing of columns and rows) • Specification edited by Google, Microsoft, Mozilla 24
in Trident (IE) • Blink (Chrome): work in progress (Google and Igalia) • WebKit (Safari): work in progress (Igalia) • Gecko (Firefox): work in progress (started early this year) 30
apps as if they were native • Killer feature of web apps: can be used without installation (e.g. just once) Formats: • Hosted app: collection of web-hosted assets plus… • App manifest • Cache manifest • Packaged app (with app manifest, no cache manifest needed) • Needed for signing (and thus app stores) Publishing: • App store/marketplace! • Self-publishing 32
app installation supported by OS: • Android • iOS • Windows Phone Generate native apps via Firefox and Chrome (if in Chrome Web Store): • Windows • OS X • Linux Web apps are native apps: • Chrome OS • Firefox OS Platforms supported by Cordova: Amazon Fire OS, Android, Firefox OS, iOS, Ubuntu, Windows Phone, Windows, and others. ! ! 33
Writing reusable widgets for HTML is hard (example: social buttons). 㱺 frameworks • Many incompatible frameworks! Solution:! • Web Components • Suite of APIs, provides infrastructure for widgets 36
Shadow DOM: encapsulate the DOM of widgets (=nest documents) • Custom Elements: define both appearance and behavior • HTML Imports: package HTML (HTML, CSS, templates, scripts) 㱺 useful for packaging custom elements Polyfills for current browsers: • Google Polymer • Mozilla X-Tag 37
id="mytemplate"> <img src="" alt="great image"> <div class="comment"></div> </template> • Templates can be placed almost anywhere. • Content is inactive: • Not considered part of the document 㱺 no actions are triggered (by images, CSS, scripts) • Invisible 38
image"> <div class="comment"></div> </template> ! ! var t = document.querySelector('#mytemplate'); ! // Fill in data t.content.querySelector('img').src = 'logo.png'; ! // Add to document var clone = document.importNode(t.content, true); document.body.appendChild(clone); 39
CSS of widget leaks into surrounding document (and vice versa). • IDs and classes • Style rules • Shadow DOM encapsulates HTML and CSS via nested documents. 40
{ ! // Template var t = document.querySelector('#foo-template'); var clone = document.importNode(t.content, true); ! // Shadow DOM this.createShadowRoot().appendChild(clone); }, 45
HTML: <x-foo></x-foo> Via document.createElement(): var xFoo = document.createElement('x-foo'); xFoo.addEventListener('click', function(e) { alert('Thanks!'); }); Via the constructor: var xFoo = new XFoo(); document.body.appendChild(xFoo); 46
• The next versions of Ember.js and AngularJS will be based on Web Components. • Blink is considering supporting the legacy <marquee> tag via a web component. • Timestamps on GitHub: via a Custom Element and Polymer polyfill. 49
for a common ecosystem for widgets. • Considerable momentum: • Certain at Mozilla and Google, under consideration at Microsoft • Next versions of AngularJS, Ember.js are based on Web Components 50
Availability More speed asm.js Now ParallelJS Work in progress Broader ecosystem ECMAScript 6 (classes, modules) Now (compile to ES5) Web Components Now (polyfill) Help with GUIs and apps Web Components Now (polyfill) CSS Grid Layout Soon Installable web apps Now
between JavaScript and native” by A.R. • “ParallelJS: data parallelism for JavaScript” by A.R. • “ECMAScript 6: what’s next for JavaScript?” by A.R. (slides) • “CSS Grid Layout Module Level 1” by Tab Atkins Jr., fantasai, Rossen Atanassov (W3C Editor’s Draft) • “CSS Grid Layout. Specification overview. Implementation status and roadmap” by Manuel Rego (slides) • “Installing web apps natively” by A.R. • WebComponents.org: site with resources Bonus: “Speaking JavaScript” by A.R. (free online book) 54