21
Ignore the DOM Paul Bakaus, Liferay

Ignore the DOM (German)

Embed Size (px)

DESCRIPTION

Seitdem es das DOM gibt, ist JavaScript eine gehasste Sprache. Dabei ist JavaScript selbst eigentlich trotz seiner Flexibilität extrem performant - nur die Zusammenarbeit mit dem Document Object Model bremst die Performance. In dieser Session lernen Sie nicht, wie sie den Zugriff auf Elemente im DOM z.B. mit jQuery optimieren, sondern wie sie ihn fast komplett von der Liste streichen können.

Citation preview

Page 1: Ignore the DOM (German)

Ignore the DOMPaul Bakaus, Liferay

Page 2: Ignore the DOM (German)

Warum ist JavaScript langsam?

2Paul Bakaus, Liferay

Page 3: Ignore the DOM (German)

JS Performance Stack

3Paul Bakaus, Liferay

JavaScript

Rendering

DOM

CSS

Im Browser angezeigt

Page 4: Ignore the DOM (German)

JS Performance Stack

4Paul Bakaus, Liferay

JavaScript

Parsing

DOM

CSS

Gerenderte Representation

Page 5: Ignore the DOM (German)

JS Performance Stack

‣ JavaScript selbst macht JavaScript nicht langsam

‣ Wenn wir Parsing/Rendering vergessen könnten, wäre JavaScript extrem schnell

5Paul Bakaus, Liferay

Awwww!How I hatethe DOM!

Page 6: Ignore the DOM (German)

Aber wenn wir das wirklich versuchten..

6Paul Bakaus, Liferay

Page 7: Ignore the DOM (German)

..hätten wir eine wunderschöne command line application!

7Paul Bakaus, Liferay

Page 8: Ignore the DOM (German)

Was können wir machen?

8Paul Bakaus, Liferay

Page 9: Ignore the DOM (German)

Können wir CSS entfernen?

‣ CSS macht unsere Seiten hübsch

‣ DOM Layer 2 für Stylesheets ist eigentlich ziemlich schnell

9Paul Bakaus, Liferay

No way!

Page 10: Ignore the DOM (German)

Was ist mit dem DOM?

‣ Das DOM gibt uns Repräsentationen unserer sichtbaren Elemente in JS

‣ Es wird für eine Vielzahl von Anwendungen benutzt, sehr häufig um Elemente zu selektieren und zu verändern

10Paul Bakaus, Liferay

Page 11: Ignore the DOM (German)

Two systems

11Paul Bakaus, Liferay

Isolierte Umgebung Offene Umgebung

ExterneQuelle

Externe Quelle

Page 12: Ignore the DOM (German)

Two systems

12Paul Bakaus, Liferay

Isolierte Umgebung Offene Umgebung

Externalsource

Externalsource

Page 13: Ignore the DOM (German)

Old School!

13Paul Bakaus, Liferay

Bau dir angepasste Lösungen!

Warte mal!Für sowas hab ich keine Zeit!

..dann benutz ne Library!

..aber das frisst immer nochzu viel Zeit :(

denkste!

Page 14: Ignore the DOM (German)

Ein Beispiel mit jQuery

14Paul Bakaus, Liferay

Page 15: Ignore the DOM (German)

Patterns

15Paul Bakaus, Liferay

Page 16: Ignore the DOM (German)

Canvas

‣ Stell dir vor du arbeitest in einem <canvas> Element

‣ Kein DOM

‣ Kein Event System

16Paul Bakaus, Liferay

plane jetzt, was du wirklich brauchst

Page 17: Ignore the DOM (German)

Mutation events

‣ DOMNodeInserted

‣ DOMNodeRemoved

‣ DOMAttrModified

17Paul Bakaus, Liferay

‣ onpropertychange

W3C IE

Page 18: Ignore the DOM (German)

..mehr

‣ Bau dir dein eigenes Event Model (durch Delegation)

‣ Controlliere den Output - merke dir, wieviele Elemente dein Script hinzufügt

18Paul Bakaus, Liferay

Page 19: Ignore the DOM (German)

..noch mehr

‣ Soviel wie möglich cachen

‣ In Frameworks/Libraries Selektoren und Offsets weiterverwenden

‣ Mit Template Nodes arbeiten

19Paul Bakaus, Liferay

Page 20: Ignore the DOM (German)

20Paul Bakaus, Liferay

Vielen Dank für die Aufmerksamkeit!

Page 21: Ignore the DOM (German)

Kontakt

[email protected]

‣ paulbakaus.com

21Paul Bakaus, Liferay