caching mit contao 4 · terminal42 web development gmbh contao/core-bundle (pre monorepo) ⁃ 576...

64
terminal42 web development gmbh für AnwenderInnen Caching mit Contao 4.8 Contao Konferenz 2019

Upload: others

Post on 08-Oct-2020

2 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Caching mit Contao 4 · terminal42 web development gmbh contao/core-bundle (pre Monorepo) ⁃ 576 ⁃ 577 ⁃ 742 ⁃ 743 ⁃ 1263 ⁃ 1388 (leofeyer) ⁃ 1478 ⁃ 1611 ⁃ 1612 ⁃

terminal42 web development gmbh

für AnwenderInnen

Caching mit Contao 4.8

Cont

ao K

onfe

renz

201

9

Page 2: Caching mit Contao 4 · terminal42 web development gmbh contao/core-bundle (pre Monorepo) ⁃ 576 ⁃ 577 ⁃ 742 ⁃ 743 ⁃ 1263 ⁃ 1388 (leofeyer) ⁃ 1478 ⁃ 1611 ⁃ 1612 ⁃

terminal42 web development gmbh

contao/core-bundle (pre Monorepo)

⁃ 576⁃ 577⁃ 742⁃ 743⁃ 1263⁃ 1388 (leofeyer)⁃ 1478⁃ 1611⁃ 1612⁃ 1630 (aschempp)

Warum ich?

• Der erste Pull Request im Bezug auf Caching auf den Monat genau vor 3 Jahren. Damals Contao 4.3.

friendsofsymfony/http-cache

⁃ 373⁃ 419⁃ 422⁃ 423⁃ 437

friendsofsymfony/http-cache-bundle

⁃ 363⁃ 435

toflar/psr6-symfony-http-cache-store

⁃ 45 Commits seit 27.09.2017 symfony/symfony

⁃ 22079 (ausi)⁃ 24075⁃ 25583⁃ 26532 (aschempp)⁃ 27309⁃ 32455

contao/contao

⁃ 117⁃ 137⁃ 147⁃ 148⁃ 173⁃ 351⁃ 365⁃ 389⁃ 469 (ausi)⁃ 482⁃ 483 (aschempp)⁃ 592 (aschempp)⁃ 611

Page 3: Caching mit Contao 4 · terminal42 web development gmbh contao/core-bundle (pre Monorepo) ⁃ 576 ⁃ 577 ⁃ 742 ⁃ 743 ⁃ 1263 ⁃ 1388 (leofeyer) ⁃ 1478 ⁃ 1611 ⁃ 1612 ⁃

terminal42 web development gmbh

Für AnwenderInnen?

• Nicht für EndanwenderInnen, die den Inhalt bearbeiten.

• Sondern für fortgeschriCene Contao-Administratoren, die die Webseite betreuen.

• = Es wird technisch, aber ihr wollt ja auch etwas mehr wissen, als die EndanwenderInnen! :-)

Page 4: Caching mit Contao 4 · terminal42 web development gmbh contao/core-bundle (pre Monorepo) ⁃ 576 ⁃ 577 ⁃ 742 ⁃ 743 ⁃ 1263 ⁃ 1388 (leofeyer) ⁃ 1478 ⁃ 1611 ⁃ 1612 ⁃

terminal42 web development gmbh

Es ändert sich doch eh wieder!• NEIN!

• Okay, die einzige Konstante ist der Wandel aber…

• …zum ersten Mal so richGg happy mit dem was wir haben!

• …keine Änderungen für die 4.9 in Aussicht was das Handling nach aussen hin angeht.

• …bestes Caching-Framework aller CMSe dieser Welt! 😏

• ✏ 📜

Page 5: Caching mit Contao 4 · terminal42 web development gmbh contao/core-bundle (pre Monorepo) ⁃ 576 ⁃ 577 ⁃ 742 ⁃ 743 ⁃ 1263 ⁃ 1388 (leofeyer) ⁃ 1478 ⁃ 1611 ⁃ 1612 ⁃

terminal42 web development gmbh

Back to the basics

Page 6: Caching mit Contao 4 · terminal42 web development gmbh contao/core-bundle (pre Monorepo) ⁃ 576 ⁃ 577 ⁃ 742 ⁃ 743 ⁃ 1263 ⁃ 1388 (leofeyer) ⁃ 1478 ⁃ 1611 ⁃ 1612 ⁃

terminal42 web development gmbh

Back to the basics

Page 7: Caching mit Contao 4 · terminal42 web development gmbh contao/core-bundle (pre Monorepo) ⁃ 576 ⁃ 577 ⁃ 742 ⁃ 743 ⁃ 1263 ⁃ 1388 (leofeyer) ⁃ 1478 ⁃ 1611 ⁃ 1612 ⁃

terminal42 web development gmbh

RequestGET /de/ HTTP/1.1Cookie: PHPSESSID=……Host: contao.orgConnection: closeUser-Agent: Mozilla/5.0 (…) Gecko/20100101 Firefox/69.0Accept: text/html

Page 8: Caching mit Contao 4 · terminal42 web development gmbh contao/core-bundle (pre Monorepo) ⁃ 576 ⁃ 577 ⁃ 742 ⁃ 743 ⁃ 1263 ⁃ 1388 (leofeyer) ⁃ 1478 ⁃ 1611 ⁃ 1612 ⁃

terminal42 web development gmbh

ResponseHTTP/2.0 200 OKDate: Thu, 09 Oct 2019 12:42:00 GMTContent-Length: 88Content-Type: text/htmlCache-Control: no-cache

<html><body><h1>Hello, World!</h1></body></html>

Page 9: Caching mit Contao 4 · terminal42 web development gmbh contao/core-bundle (pre Monorepo) ⁃ 576 ⁃ 577 ⁃ 742 ⁃ 743 ⁃ 1263 ⁃ 1388 (leofeyer) ⁃ 1478 ⁃ 1611 ⁃ 1612 ⁃

terminal42 web development gmbh

Browser

Server

Private Cache

Browser

Private Cache

Page 10: Caching mit Contao 4 · terminal42 web development gmbh contao/core-bundle (pre Monorepo) ⁃ 576 ⁃ 577 ⁃ 742 ⁃ 743 ⁃ 1263 ⁃ 1388 (leofeyer) ⁃ 1478 ⁃ 1611 ⁃ 1612 ⁃

terminal42 web development gmbh

Browser

Server

Private Cache

Browser

Private Cache

Proxy

Shared/Public Cache

Page 11: Caching mit Contao 4 · terminal42 web development gmbh contao/core-bundle (pre Monorepo) ⁃ 576 ⁃ 577 ⁃ 742 ⁃ 743 ⁃ 1263 ⁃ 1388 (leofeyer) ⁃ 1478 ⁃ 1611 ⁃ 1612 ⁃

terminal42 web development gmbh

KonfiguraGonin Contao

Page 12: Caching mit Contao 4 · terminal42 web development gmbh contao/core-bundle (pre Monorepo) ⁃ 576 ⁃ 577 ⁃ 742 ⁃ 743 ⁃ 1263 ⁃ 1388 (leofeyer) ⁃ 1478 ⁃ 1611 ⁃ 1612 ⁃

terminal42 web development gmbh

HTTP/2.0 200 OKDate: Thu, 09 Oct 2019 12:42:00 GMTContent-Length: 88Content-Type: text/htmlCache-Control: private, max-age=1800 Vary: Cookie

<html><body><h1>Hello, World!</h1></body></html>

Page 13: Caching mit Contao 4 · terminal42 web development gmbh contao/core-bundle (pre Monorepo) ⁃ 576 ⁃ 577 ⁃ 742 ⁃ 743 ⁃ 1263 ⁃ 1388 (leofeyer) ⁃ 1478 ⁃ 1611 ⁃ 1612 ⁃

terminal42 web development gmbh

HTTP/2.0 200 OKDate: Thu, 09 Oct 2019 12:42:00 GMTContent-Length: 88Content-Type: text/htmlCache-Control: public, s-maxage=3600, max-age=1800Vary: Cookie

<html><body><h1>Hello, World!</h1></body></html>

Page 14: Caching mit Contao 4 · terminal42 web development gmbh contao/core-bundle (pre Monorepo) ⁃ 576 ⁃ 577 ⁃ 742 ⁃ 743 ⁃ 1263 ⁃ 1388 (leofeyer) ⁃ 1478 ⁃ 1611 ⁃ 1612 ⁃

terminal42 web development gmbh

HTTP/2.0 200 OKDate: Thu, 09 Oct 2019 12:42:00 GMTContent-Length: 88Content-Type: text/htmlCache-Control: public, s-maxage=3600, max-age=1800Vary: Cookie

<html><body><h1>Hello, World!</h1></body></html>

Page 15: Caching mit Contao 4 · terminal42 web development gmbh contao/core-bundle (pre Monorepo) ⁃ 576 ⁃ 577 ⁃ 742 ⁃ 743 ⁃ 1263 ⁃ 1388 (leofeyer) ⁃ 1478 ⁃ 1611 ⁃ 1612 ⁃

terminal42 web development gmbh

That’s it!für die EndanwenderInnen

Page 16: Caching mit Contao 4 · terminal42 web development gmbh contao/core-bundle (pre Monorepo) ⁃ 576 ⁃ 577 ⁃ 742 ⁃ 743 ⁃ 1263 ⁃ 1388 (leofeyer) ⁃ 1478 ⁃ 1611 ⁃ 1612 ⁃

terminal42 web development gmbh

Warum überhaupt ein Cache?

• Leistung (CPU, RAM) kostet immer weniger.

• PHP OPCache wird immer besser.

• «Mein Contao ist doch auch ohne Cache schnell!»

Page 17: Caching mit Contao 4 · terminal42 web development gmbh contao/core-bundle (pre Monorepo) ⁃ 576 ⁃ 577 ⁃ 742 ⁃ 743 ⁃ 1263 ⁃ 1388 (leofeyer) ⁃ 1478 ⁃ 1611 ⁃ 1612 ⁃

terminal42 web development gmbh

Performance!• Auch wenn der Server schnell ist:

• Contao Boot-Prozess

• Rou_ng (zu welcher Seite gehört die URL)

• Datenbankabfragen für Seiten, Ar_kel, Module, Inhaltselemente

• Template Rendering

• Performance is about conversion rates and SEO(PageSpeed, Lighthouse, …)

• Performance is about UX! Performance is about the users!

Page 18: Caching mit Contao 4 · terminal42 web development gmbh contao/core-bundle (pre Monorepo) ⁃ 576 ⁃ 577 ⁃ 742 ⁃ 743 ⁃ 1263 ⁃ 1388 (leofeyer) ⁃ 1478 ⁃ 1611 ⁃ 1612 ⁃

terminal42 web development gmbh

Page 19: Caching mit Contao 4 · terminal42 web development gmbh contao/core-bundle (pre Monorepo) ⁃ 576 ⁃ 577 ⁃ 742 ⁃ 743 ⁃ 1263 ⁃ 1388 (leofeyer) ⁃ 1478 ⁃ 1611 ⁃ 1612 ⁃

terminal42 web development gmbh

Wozu der Umbau?Der eingebaute HTML-Cache in der 3.5 war doch okay?

Page 20: Caching mit Contao 4 · terminal42 web development gmbh contao/core-bundle (pre Monorepo) ⁃ 576 ⁃ 577 ⁃ 742 ⁃ 743 ⁃ 1263 ⁃ 1388 (leofeyer) ⁃ 1478 ⁃ 1611 ⁃ 1612 ⁃

terminal42 web development gmbh

Standards sind toll!

• Masseinheiten

• DIN

• ISO

• RFC

Page 21: Caching mit Contao 4 · terminal42 web development gmbh contao/core-bundle (pre Monorepo) ⁃ 576 ⁃ 577 ⁃ 742 ⁃ 743 ⁃ 1263 ⁃ 1388 (leofeyer) ⁃ 1478 ⁃ 1611 ⁃ 1612 ⁃

terminal42 web development gmbh

Browser

Server

Browser

Proxy

Page 22: Caching mit Contao 4 · terminal42 web development gmbh contao/core-bundle (pre Monorepo) ⁃ 576 ⁃ 577 ⁃ 742 ⁃ 743 ⁃ 1263 ⁃ 1388 (leofeyer) ⁃ 1478 ⁃ 1611 ⁃ 1612 ⁃

terminal42 web development gmbh

Browser

Server

Browser

Proxy

Page 23: Caching mit Contao 4 · terminal42 web development gmbh contao/core-bundle (pre Monorepo) ⁃ 576 ⁃ 577 ⁃ 742 ⁃ 743 ⁃ 1263 ⁃ 1388 (leofeyer) ⁃ 1478 ⁃ 1611 ⁃ 1612 ⁃

terminal42 web development gmbh

Browser

Server

Browser

Proxy

Page 24: Caching mit Contao 4 · terminal42 web development gmbh contao/core-bundle (pre Monorepo) ⁃ 576 ⁃ 577 ⁃ 742 ⁃ 743 ⁃ 1263 ⁃ 1388 (leofeyer) ⁃ 1478 ⁃ 1611 ⁃ 1612 ⁃

terminal42 web development gmbh

Browser

Server

Browser

Proxy

Proxy

Proxy

Page 25: Caching mit Contao 4 · terminal42 web development gmbh contao/core-bundle (pre Monorepo) ⁃ 576 ⁃ 577 ⁃ 742 ⁃ 743 ⁃ 1263 ⁃ 1388 (leofeyer) ⁃ 1478 ⁃ 1611 ⁃ 1612 ⁃

terminal42 web development gmbh

Browser

Server

Browser

Proxy

Proxy

Proxy

Proxy

Page 26: Caching mit Contao 4 · terminal42 web development gmbh contao/core-bundle (pre Monorepo) ⁃ 576 ⁃ 577 ⁃ 742 ⁃ 743 ⁃ 1263 ⁃ 1388 (leofeyer) ⁃ 1478 ⁃ 1611 ⁃ 1612 ⁃

terminal42 web development gmbh

Page 27: Caching mit Contao 4 · terminal42 web development gmbh contao/core-bundle (pre Monorepo) ⁃ 576 ⁃ 577 ⁃ 742 ⁃ 743 ⁃ 1263 ⁃ 1388 (leofeyer) ⁃ 1478 ⁃ 1611 ⁃ 1612 ⁃

terminal42 web development gmbh

Der Shared Cacheist worüber wir heute sprechen!

Page 28: Caching mit Contao 4 · terminal42 web development gmbh contao/core-bundle (pre Monorepo) ⁃ 576 ⁃ 577 ⁃ 742 ⁃ 743 ⁃ 1263 ⁃ 1388 (leofeyer) ⁃ 1478 ⁃ 1611 ⁃ 1612 ⁃

terminal42 web development gmbh

Page 29: Caching mit Contao 4 · terminal42 web development gmbh contao/core-bundle (pre Monorepo) ⁃ 576 ⁃ 577 ⁃ 742 ⁃ 743 ⁃ 1263 ⁃ 1388 (leofeyer) ⁃ 1478 ⁃ 1611 ⁃ 1612 ⁃

terminal42 web development gmbh

Nicht cachebarHTTP/2.0 200 OKDate: Thu, 09 Oct 2019 12:42:00 GMTContent-Length: 88Content-Type: text/htmlContao-Cache: missAge: 0

<html><body><h1>Hello, World!</h1></body></html>

Page 30: Caching mit Contao 4 · terminal42 web development gmbh contao/core-bundle (pre Monorepo) ⁃ 576 ⁃ 577 ⁃ 742 ⁃ 743 ⁃ 1263 ⁃ 1388 (leofeyer) ⁃ 1478 ⁃ 1611 ⁃ 1612 ⁃

terminal42 web development gmbh

Wird neu gecachedHTTP/2.0 200 OKDate: Thu, 09 Oct 2019 12:42:00 GMTContent-Length: 88Content-Type: text/htmlContao-Cache: miss/storeAge: 0

<html><body><h1>Hello, World!</h1></body></html>

Page 31: Caching mit Contao 4 · terminal42 web development gmbh contao/core-bundle (pre Monorepo) ⁃ 576 ⁃ 577 ⁃ 742 ⁃ 743 ⁃ 1263 ⁃ 1388 (leofeyer) ⁃ 1478 ⁃ 1611 ⁃ 1612 ⁃

terminal42 web development gmbh

Aus dem CacheHTTP/2.0 200 OKDate: Thu, 09 Oct 2019 12:42:00 GMTContent-Length: 88Content-Type: text/htmlContao-Cache: freshAge: 42

<html><body><h1>Hello, World!</h1></body></html>

Page 32: Caching mit Contao 4 · terminal42 web development gmbh contao/core-bundle (pre Monorepo) ⁃ 576 ⁃ 577 ⁃ 742 ⁃ 743 ⁃ 1263 ⁃ 1388 (leofeyer) ⁃ 1478 ⁃ 1611 ⁃ 1612 ⁃

terminal42 web development gmbh

ProblemaGk #1Wie erkennen wir ob ein Benutzer eingeloggt ist?

Page 33: Caching mit Contao 4 · terminal42 web development gmbh contao/core-bundle (pre Monorepo) ⁃ 576 ⁃ 577 ⁃ 742 ⁃ 743 ⁃ 1263 ⁃ 1388 (leofeyer) ⁃ 1478 ⁃ 1611 ⁃ 1612 ⁃

terminal42 web development gmbh

Problemstellung

• Contao muss dem Cache mifeilen können, dass er hfps://www.domain.de/login.html anders cachen soll, je nach dem ob ich eingeloggt bin oder nicht. Ansonsten würde immer das Login-Formular angezeigt, staf «eingeloggt als k.jones».

Page 34: Caching mit Contao 4 · terminal42 web development gmbh contao/core-bundle (pre Monorepo) ⁃ 576 ⁃ 577 ⁃ 742 ⁃ 743 ⁃ 1263 ⁃ 1388 (leofeyer) ⁃ 1478 ⁃ 1611 ⁃ 1612 ⁃

terminal42 web development gmbh

Der Vary-Header

• Teilt dem Cache mit, unterschiedliche Varianten pro URI abzulegen.

• Man merke sich: «Hallo Cache, bife vary-iere» $😉

Page 35: Caching mit Contao 4 · terminal42 web development gmbh contao/core-bundle (pre Monorepo) ⁃ 576 ⁃ 577 ⁃ 742 ⁃ 743 ⁃ 1263 ⁃ 1388 (leofeyer) ⁃ 1478 ⁃ 1611 ⁃ 1612 ⁃

terminal42 web development gmbh

Der Vary-Header

GET /hello-worldAccept: text/html

HTTP/2.0 200 OKCache-Control: public, s-maxage=300Vary: Accept

<html><body><h1>Hello, World!</h1></body></html>

Ich darf diesen Eintrag für 300 Sekunden cachen, aber nur dann ausliefern, wenn der Request den

Header «Accept» mit dem exakten (!) Inhalt «text/html» enthält!

Page 36: Caching mit Contao 4 · terminal42 web development gmbh contao/core-bundle (pre Monorepo) ⁃ 576 ⁃ 577 ⁃ 742 ⁃ 743 ⁃ 1263 ⁃ 1388 (leofeyer) ⁃ 1478 ⁃ 1611 ⁃ 1612 ⁃

terminal42 web development gmbh

Der Vary-Header

GET /hello-worldAccept: application/json

HTTP/2.0 200 OKCache-Control: public, s-maxage=300Vary: Accept

{ “body”: “Hello World!”}

Ich darf diesen Eintrag für 300 Sekunden cachen, aber nur dann ausliefern, wenn der Request den

Header «Accept» mit dem exakten (!) Inhalt «application/json» enthält!

Page 37: Caching mit Contao 4 · terminal42 web development gmbh contao/core-bundle (pre Monorepo) ⁃ 576 ⁃ 577 ⁃ 742 ⁃ 743 ⁃ 1263 ⁃ 1388 (leofeyer) ⁃ 1478 ⁃ 1611 ⁃ 1612 ⁃

terminal42 web development gmbh

Nicht eingeloggt

GET /hello-worldAccept: text/html

HTTP/2.0 200 OKCache-Control: public, s-maxage=300Vary: Cookie

Page 38: Caching mit Contao 4 · terminal42 web development gmbh contao/core-bundle (pre Monorepo) ⁃ 576 ⁃ 577 ⁃ 742 ⁃ 743 ⁃ 1263 ⁃ 1388 (leofeyer) ⁃ 1478 ⁃ 1611 ⁃ 1612 ⁃

terminal42 web development gmbh

Eingeloggt

GET /hello-worldAccept: text/htmlCookie: PHPSESSID=b7a861e4ae0664b3a82ec2fbf239e5ff

HTTP/2.0 200 OKCache-Control: private, no-storeVary: Cookie

Page 39: Caching mit Contao 4 · terminal42 web development gmbh contao/core-bundle (pre Monorepo) ⁃ 576 ⁃ 577 ⁃ 742 ⁃ 743 ⁃ 1263 ⁃ 1388 (leofeyer) ⁃ 1478 ⁃ 1611 ⁃ 1612 ⁃

terminal42 web development gmbh

HTTP/2.0 200 OKDate: Thu, 09 Oct 2019 12:42:00 GMTContent-Length: 88Content-Type: text/htmlCache-Control: public, s-maxage=3600, max-age=1800Vary: Cookie

<html><body><h1>Hello, World!</h1></body></html>

Nicht eingeloggt

Page 40: Caching mit Contao 4 · terminal42 web development gmbh contao/core-bundle (pre Monorepo) ⁃ 576 ⁃ 577 ⁃ 742 ⁃ 743 ⁃ 1263 ⁃ 1388 (leofeyer) ⁃ 1478 ⁃ 1611 ⁃ 1612 ⁃

terminal42 web development gmbh

ProblemaGk #2Frontend-Vorschau

Page 41: Caching mit Contao 4 · terminal42 web development gmbh contao/core-bundle (pre Monorepo) ⁃ 576 ⁃ 577 ⁃ 742 ⁃ 743 ⁃ 1263 ⁃ 1388 (leofeyer) ⁃ 1478 ⁃ 1611 ⁃ 1612 ⁃

terminal42 web development gmbh

Die preview.php

• web/index.php

• web/preview.php

• Frontend-Vorschau:hfps://www.domain.de/preview.php/profil.html

Page 42: Caching mit Contao 4 · terminal42 web development gmbh contao/core-bundle (pre Monorepo) ⁃ 576 ⁃ 577 ⁃ 742 ⁃ 743 ⁃ 1263 ⁃ 1388 (leofeyer) ⁃ 1478 ⁃ 1611 ⁃ 1612 ⁃

terminal42 web development gmbh

ProblemaGk #3Cookies

Page 43: Caching mit Contao 4 · terminal42 web development gmbh contao/core-bundle (pre Monorepo) ⁃ 576 ⁃ 577 ⁃ 742 ⁃ 743 ⁃ 1263 ⁃ 1388 (leofeyer) ⁃ 1478 ⁃ 1611 ⁃ 1612 ⁃

terminal42 web development gmbh

ProblemaGk• Vary bezieht sich immer auf den Header und dessen gesamten Inhalt.

• Sowas wie «Vary: Cookie=PHPSESSID» exis_ert nicht.

• (es gab mal einen Key-Header Draj der das ändern sollte aber dieser hat es leider nie über den Draj-Status hinaus geschal…)

• Ergo: Wir können nicht auf bes_mmte Cookies vary-en. Der Cache ist somit nicht in der Lage irrelevante von relevanten Cookies zu unterscheiden. Caching wird somit deakGviert, sobald mindestens ein Cookie vorhanden ist!

• irrelevant = hat keinen Einfluss auf den Cache und soll somit eigentlich nicht berücksich_gt werden.

• relevant = hat Einfluss auf den Cache und soll berücksich_gt werden.

Page 44: Caching mit Contao 4 · terminal42 web development gmbh contao/core-bundle (pre Monorepo) ⁃ 576 ⁃ 577 ⁃ 742 ⁃ 743 ⁃ 1263 ⁃ 1388 (leofeyer) ⁃ 1478 ⁃ 1611 ⁃ 1612 ⁃

terminal42 web development gmbh

Irrelevante Cookies?

• GDPR-Cookiebar, die am HTML nichts ändert

• Google Analy_cs

• Matomo (Piwik)

• Facebook Pixel

• Cloudflare

• uvm.

Page 45: Caching mit Contao 4 · terminal42 web development gmbh contao/core-bundle (pre Monorepo) ⁃ 576 ⁃ 577 ⁃ 742 ⁃ 743 ⁃ 1263 ⁃ 1388 (leofeyer) ⁃ 1478 ⁃ 1611 ⁃ 1612 ⁃

terminal42 web development gmbh

Lösung• Blacklist, Contao kennt eine interne Liste an irrelevanten Cookies und

löscht diese bevor der Cache gefragt wird. (siehe «StripCookiesSubscriber»)

• '(.*)?modal(.*)?'

• '_ga'

• '_pk_id'

• '_rp'

• Whitelist, kann per Umgebungsvariable konfiguriert werden und übersteuert die mitgelieferte Blacklist.

Page 46: Caching mit Contao 4 · terminal42 web development gmbh contao/core-bundle (pre Monorepo) ⁃ 576 ⁃ 577 ⁃ 742 ⁃ 743 ⁃ 1263 ⁃ 1388 (leofeyer) ⁃ 1478 ⁃ 1611 ⁃ 1612 ⁃

terminal42 web development gmbh

Page 47: Caching mit Contao 4 · terminal42 web development gmbh contao/core-bundle (pre Monorepo) ⁃ 576 ⁃ 577 ⁃ 742 ⁃ 743 ⁃ 1263 ⁃ 1388 (leofeyer) ⁃ 1478 ⁃ 1611 ⁃ 1612 ⁃

terminal42 web development gmbh

Informiert die Entwickler

• Cookies werden zu 90%* falsch eingesetzt!

• Wenn der Server die Informa_on nicht verwertet, braucht es kein Cookie! Teilt ihm keine Informa_onen mit, die er nicht gebrauchen kann!

• JavaScript kann sessionStorage, localStorage (Vorsicht: blocking API, also synchron) oder IndexedDB nutzen!

• Meinen Blogpost lesen: hfps://contao.org/de/news/die-jagd-auf-ueberfluessige-cookies.html

* Yanick’sche Sta_s_k

Page 48: Caching mit Contao 4 · terminal42 web development gmbh contao/core-bundle (pre Monorepo) ⁃ 576 ⁃ 577 ⁃ 742 ⁃ 743 ⁃ 1263 ⁃ 1388 (leofeyer) ⁃ 1478 ⁃ 1611 ⁃ 1612 ⁃

terminal42 web development gmbh

Relevante Cookies?

• PHPSESSID (PHP Session)

• Potenziell persönliche Daten (Session !== eingeloggt als User)

• CSRF-Schutz

• A/B-Tes_ng

• Google Analy_cs Daten werden vom Server ausgewertet

Page 49: Caching mit Contao 4 · terminal42 web development gmbh contao/core-bundle (pre Monorepo) ⁃ 576 ⁃ 577 ⁃ 742 ⁃ 743 ⁃ 1263 ⁃ 1388 (leofeyer) ⁃ 1478 ⁃ 1611 ⁃ 1612 ⁃

terminal42 web development gmbh

Whitelist

• Entweder als echte Umgebungsvariable

• Oder .env-Datei im Wurzelverzeichnis

COOKIE_WHITELIST=PHPSESSID,csrf_https-contao_csrf_token

Page 50: Caching mit Contao 4 · terminal42 web development gmbh contao/core-bundle (pre Monorepo) ⁃ 576 ⁃ 577 ⁃ 742 ⁃ 743 ⁃ 1263 ⁃ 1388 (leofeyer) ⁃ 1478 ⁃ 1611 ⁃ 1612 ⁃

terminal42 web development gmbh

Bonus 1Performance-Vergleiche

Page 51: Caching mit Contao 4 · terminal42 web development gmbh contao/core-bundle (pre Monorepo) ⁃ 576 ⁃ 577 ⁃ 742 ⁃ 743 ⁃ 1263 ⁃ 1388 (leofeyer) ⁃ 1478 ⁃ 1611 ⁃ 1612 ⁃

terminal42 web development gmbh

Eingebauter Cache

Page 52: Caching mit Contao 4 · terminal42 web development gmbh contao/core-bundle (pre Monorepo) ⁃ 576 ⁃ 577 ⁃ 742 ⁃ 743 ⁃ 1263 ⁃ 1388 (leofeyer) ⁃ 1478 ⁃ 1611 ⁃ 1612 ⁃

terminal42 web development gmbh

Varnish

Page 53: Caching mit Contao 4 · terminal42 web development gmbh contao/core-bundle (pre Monorepo) ⁃ 576 ⁃ 577 ⁃ 742 ⁃ 743 ⁃ 1263 ⁃ 1388 (leofeyer) ⁃ 1478 ⁃ 1611 ⁃ 1612 ⁃

terminal42 web development gmbh

Bonus 2Das beste Caching-Framework!

Page 54: Caching mit Contao 4 · terminal42 web development gmbh contao/core-bundle (pre Monorepo) ⁃ 576 ⁃ 577 ⁃ 742 ⁃ 743 ⁃ 1263 ⁃ 1388 (leofeyer) ⁃ 1478 ⁃ 1611 ⁃ 1612 ⁃

terminal42 web development gmbh

Browser

Server

Browser

Proxy

Bekannte Server / Zugriff möglich

Unbekannte Clients / Zugriff nicht möglich

Page 55: Caching mit Contao 4 · terminal42 web development gmbh contao/core-bundle (pre Monorepo) ⁃ 576 ⁃ 577 ⁃ 742 ⁃ 743 ⁃ 1263 ⁃ 1388 (leofeyer) ⁃ 1478 ⁃ 1611 ⁃ 1612 ⁃

terminal42 web development gmbh

Browser

Server

Browser

Proxy

Unbekannte Clients / Zugriff nicht möglich

Bekannte Server / Zugriff möglich

Page 56: Caching mit Contao 4 · terminal42 web development gmbh contao/core-bundle (pre Monorepo) ⁃ 576 ⁃ 577 ⁃ 742 ⁃ 743 ⁃ 1263 ⁃ 1388 (leofeyer) ⁃ 1478 ⁃ 1611 ⁃ 1612 ⁃

terminal42 web development gmbh

Cache TaggingHTTP/2.0 200 OKDate: Thu, 09 Oct 2019 12:42:00 GMTContent-Length: 88Content-Type: text/htmlCache-Control: public, s-maxage=1800 X-Cache-Tags: contao.db.tl_article.489,contao.db.tl_content.2180,contao.db.tl_content.2182,contao.db.tl_content.2184,contao.db.tl_content.2186,contao.db.tl_content.2185,contao.db.tl_content.2183,contao.db.tl_content.2181,contao.db.tl_module.489,contao.db.tl_module.,contao.db.tl_article.386,contao.db.tl_content.793,contao.db.tl_content.779,contao.db.tl_content.781,contao.db.tl_content.783,contao.db.tl_content.782,contao.db.tl_content.784,contao.db.tl_content.780,contao.db.tl_content.785,contao.db.tl_content.786,contao.db.tl_content.794,contao.db.tl_content.791,contao.db.tl_content.787,contao.db.tl_content.792,contao.db.tl_module.386,contao.db.tl_article.387,contao.db.tl_content.795,contao.db.tl_content.797,contao.db.tl_content.801,contao.db.tl_content.802,contao.db.tl_module.2,contao.db.tl_content.798,contao.db.tl_content.799,contao.db.tl_content.803,contao.db.tl_content.800,contao.db.tl_content.796,contao.db.tl_module.387,contao.db.tl_page.22

<html><body><h1>Hello, World!</h1></body></html>

Page 57: Caching mit Contao 4 · terminal42 web development gmbh contao/core-bundle (pre Monorepo) ⁃ 576 ⁃ 577 ⁃ 742 ⁃ 743 ⁃ 1263 ⁃ 1388 (leofeyer) ⁃ 1478 ⁃ 1611 ⁃ 1612 ⁃

terminal42 web development gmbh

Cache Tag Purging

ServerProxy

PURGE / HTTP/1.1Host: localhostX-Cache-Tags: contao.db.tl_content.42

Page 58: Caching mit Contao 4 · terminal42 web development gmbh contao/core-bundle (pre Monorepo) ⁃ 576 ⁃ 577 ⁃ 742 ⁃ 743 ⁃ 1263 ⁃ 1388 (leofeyer) ⁃ 1478 ⁃ 1611 ⁃ 1612 ⁃

terminal42 web development gmbh

Contao IntegraGon• Sendet beim Edi_eren automa_sch Cache-Tag-Invalida_on-

Requests nach dem Schema

• contao.db.<Tabelle>

• contao.db.<Tabelle>.<ID>

• Erweiterbar durch den «oninvalidate_cache_tags_callback»

• Beispielsweise invalidiert das «comments-bundle» beim Edi_eren eines Kommentars die Tags der Quelle.

• Tagging im Frontend ist Aufgabe des Entwicklers

Page 59: Caching mit Contao 4 · terminal42 web development gmbh contao/core-bundle (pre Monorepo) ⁃ 576 ⁃ 577 ⁃ 742 ⁃ 743 ⁃ 1263 ⁃ 1388 (leofeyer) ⁃ 1478 ⁃ 1611 ⁃ 1612 ⁃

terminal42 web development gmbh

Video Demo

Page 60: Caching mit Contao 4 · terminal42 web development gmbh contao/core-bundle (pre Monorepo) ⁃ 576 ⁃ 577 ⁃ 742 ⁃ 743 ⁃ 1263 ⁃ 1388 (leofeyer) ⁃ 1478 ⁃ 1611 ⁃ 1612 ⁃

terminal42 web development gmbh

FOSHCpCache(Bundle)

• Symfony HfpCache mit toflar/psr6-symfony-hfp-cache-store

• Varnish

• erweiterbar, PR’s offen für

• OpenLiteSpeed

• Fastly

Page 61: Caching mit Contao 4 · terminal42 web development gmbh contao/core-bundle (pre Monorepo) ⁃ 576 ⁃ 577 ⁃ 742 ⁃ 743 ⁃ 1263 ⁃ 1388 (leofeyer) ⁃ 1478 ⁃ 1611 ⁃ 1612 ⁃

terminal42 web development gmbh

Page 62: Caching mit Contao 4 · terminal42 web development gmbh contao/core-bundle (pre Monorepo) ⁃ 576 ⁃ 577 ⁃ 742 ⁃ 743 ⁃ 1263 ⁃ 1388 (leofeyer) ⁃ 1478 ⁃ 1611 ⁃ 1612 ⁃

terminal42 web development gmbh

Zusammenfassung

• Contao 4.8 enthält - abgesehen von «der Checkbox»™ - die gleichen Cache-Einstellungsmöglichkeiten wie Contao 4.4, aber…

• …wir sind 100% standardkonform!

• …wir sind schneller out-of-the-box!

• …wir bieten ein Meer an Möglichkeiten das Setup noch schneller zu machen!

Page 63: Caching mit Contao 4 · terminal42 web development gmbh contao/core-bundle (pre Monorepo) ⁃ 576 ⁃ 577 ⁃ 742 ⁃ 743 ⁃ 1263 ⁃ 1388 (leofeyer) ⁃ 1478 ⁃ 1611 ⁃ 1612 ⁃

terminal42 web development gmbh

?

Cont

ao K

onfe

renz

201

9

Page 64: Caching mit Contao 4 · terminal42 web development gmbh contao/core-bundle (pre Monorepo) ⁃ 576 ⁃ 577 ⁃ 742 ⁃ 743 ⁃ 1263 ⁃ 1388 (leofeyer) ⁃ 1478 ⁃ 1611 ⁃ 1612 ⁃

terminal42 web development gmbh

Kontakt• Yanick Witschi / terminal42

gmbh

• Contao Core Entwickler

• API's, Performance, Caching

• Tennis, Basketball, Faustball

• Scotch

• @toflar