Web performance-play-2.3

18

Click here to load reader

description

web loading performance optimization with play 2.3 assets pipeline talk at Play Framework user group in Berlin: http://www.meetup.com/Play-Berlin-Brandenburg/events/203877602/

Transcript of Web performance-play-2.3

Page 1: Web performance-play-2.3

web performance

assets pipeline in Play 2.3

Page 2: Web performance-play-2.3

Speed is a feature

● Faster sites lead to better user engagement

● Faster sites lead to better user retention● Faster sites lead to higher conversions

Source: http://chimera.labs.oreilly.com/books/1230000000545/ch01.html#SPEED_FEATURE

Page 3: Web performance-play-2.3

better performance

● less bytes● less requests● less latency

Page 4: Web performance-play-2.3

less bytes (1)

● gzip encoding● doc:

https://www.playframework.com/documentation/latest/GzipEncoding

Page 5: Web performance-play-2.3

less bytes (2)

● conditional requests● Last-Modified and ETag headers provide

validation mechanisms

Page 6: Web performance-play-2.3

Last-Modified

● Server sets Last-Modified header● Last-Modified: Tue, 15 Nov 1994 12:45:26 GMT

● Browser issues an If-Modified-Since request header to validate the cached document

● Server answers with 304 Not Modified or 200 OK

Page 7: Web performance-play-2.3

Etag

● Server sets Etag header● Etag: "15f0fff99ed5aae4edffdd6496d7131f"

● Browser issues an If-None-Match request header to validate the cached document

● Server answers with 304 Not Modified or 200 OK

Page 8: Web performance-play-2.3

Conditional requests

● Last-modified: based on time

● Etag: based on content

● Since play 2.0.2

Page 9: Web performance-play-2.3

less requests

● Cache-Control switches on caching in the browser

● avoid requests

Page 10: Web performance-play-2.3

Cache-Control

● Cache-Control:public

● Cache-Control:private

● Cache-Control:public, max-age=31536000

● Cache-Control:public

Expires: Mon, 25 Jun 2012 21:31:12 GMT

Page 11: Web performance-play-2.3

real world

● Caching strategies different from browser to browser

Page 12: Web performance-play-2.3

perfect world

● in developement: always the last version● in production:

– cache the assets as long as they are not modified

– be sure that a browser does not use an outdated cached asset

Page 13: Web performance-play-2.3

play 2.3

● pipelineStages := Seq(digest, gzip)

● in production mode● content-based hash in the filename● different content -> different fingerprint● sets a very long cache

Page 14: Web performance-play-2.3

reduce latency

● Content delivery network (CDN)● distributes content around globe● location near from client● request without cookie● downside: one more DNS lookup

Page 15: Web performance-play-2.3

play 2.3

● webjars● pipelineStages := Seq(rjs, digest, gzip)

● assets from http://cdn.jsdelivr.net/

Page 16: Web performance-play-2.3

under the cover

● assets pipeline managed with sbt-web

and plugins: https://github.com/sbt/sbt-web

● not play specific● versioned assets controller in play 2.3

Page 17: Web performance-play-2.3

Code

https://github.com/leanovate/moodly