Slide 1

Slide 1 text

ASSET PIPELINE OPTIMIZATION by @huynhquancam

Slide 2

Slide 2 text

WHAT SHOULD YOU KNOW ABOUT THIS GUY? My name is Huynh Quan Cam. Responsible for the development and engineering of Dadadee.

Slide 3

Slide 3 text

WHAT’S THE TALK ABOUT? Rails Assets pipeline. Deploy assets pipeline on multiple servers. How to optimize the deployment?

Slide 4

Slide 4 text

ASSETS PIPELINE concatenate and minify or compress JavaScript and CSS assets. support pre-processors such as CoffeeScript, Sass and ERB. based on Sprockets.

Slide 5

Slide 5 text

USING ASSET PIPELINE

Slide 6

Slide 6 text

– The Rails core team. “TIPS OF THE DAY” You can get rid of sprockets by executing this command at the start. rails new my-awesome-app-without-sprockets --skip-sprockets

Slide 7

Slide 7 text

SITUATION we are deploying an Rails app to four servers: 2 web, 1 database and 1 worker. db and worker servers need static assets to work. zero-down time deployment and rollback required.

Slide 8

Slide 8 text

CAPISTRANO-RAILS capistrano-rails is a set of Capistrano tasks to automate Rails deployment. migrations. assets pre-compilation.

Slide 9

Slide 9 text

ORCHESTRATION SCRIPT

Slide 10

Slide 10 text

WHAT’S WRONG WITH THIS APPROACH? waste of time. waste of computing resources. waste of storage resources, especially when you’re using CDNs like CloudFront.

Slide 11

Slide 11 text

Can we only pre-compile once?

Slide 12

Slide 12 text

ASSET FINGERPRINTS generated based on file content. optimize client-side caching. better cache invalidation.

Slide 13

Slide 13 text

ASSET FINGERPRINT application.css application-908e25f4bf641868d8683022a5b62f54.css application.css application-723d1be6cc741a3aabb1cec24276d681.css

Slide 14

Slide 14 text

ASSET MANIFEST a manifest-.json cache every fingerprint of your Rails static assets. accelerate Rails helper call.

Slide 15

Slide 15 text

ASSET MANIFEST

Slide 16

Slide 16 text

NOTES fingerprints only change if file contents change. fingerprints don’t change across servers. all fingerprint requests are handled by manifest file.

Slide 17

Slide 17 text

Pre-compile once and sync the manifest file to others.

Slide 18

Slide 18 text

IMPLEMENTATION

Slide 19

Slide 19 text

IMPLEMENTATION

Slide 20

Slide 20 text

QUESTIONS?

Slide 21

Slide 21 text

THANK YOU!