The Fast, The Slow and the Lazy

Post on 16-May-2015

1.950 views 3 download

Tags:

description

Presentation about front end performance improvements with specific hints if you're running Ruby on Rails. Original presentation at the Boston-rb group in April 12, 2011

Transcript of The Fast, The Slow and the Lazy

The Fast, The Slow and the Lazy

Maurício Linhares - @mauriciojrhttp://techbot.me/

segunda-feira, 11 de abril de 2011

Who?

Java, Ruby, Objective-C, whatever

Developer at OfficeDrop.com

Agile Coach that hates scrum and loves coding

Used to sing in a Heavy Metal band

segunda-feira, 11 de abril de 2011

Where?

segunda-feira, 11 de abril de 2011

Learn to respect the HTTP protocol

What about reading the RFC?

segunda-feira, 11 de abril de 2011

A GET is, in fact, “GET a COPY”

And copying should not change your database, right?

segunda-feira, 11 de abril de 2011

When should we GET?

View information (images, movies, HTML documents)

Searching (people should be able to bookmark search results)

Web analytics (beacons and all that stuff)

segunda-feira, 11 de abril de 2011

POST is SENDING stuff to the server

And this would change your DATABASE

segunda-feira, 11 de abril de 2011

Idempotency principleMany GETs == same result

Many POSTs == not necessarily the same result

segunda-feira, 11 de abril de 2011

Google Web AcceleratorAn epic and dramatic story about how an #epic

#win becomes an #epic #fail

segunda-feira, 11 de abril de 2011

Front End OptimizationEasier than getting the Celtics to win an NBA

championship

segunda-feira, 11 de abril de 2011

Use a proxy server to deliver your content

Nginx, please

!"#$%&

!"#$%&'('

!"#$%&'')'

!"#$%&''*'

segunda-feira, 11 de abril de 2011

Define a far future expires header for all of

your static assets

segunda-feira, 11 de abril de 2011

Issues?

If you update the file, the browser will not notice;

You’ll have to rename the file or add a timestamp to tell the browser it has changed (Rails does it for you!)

/javascripts/jquery.js?12398766

segunda-feira, 11 de abril de 2011

Nginx config

location ~ ^/(images|javascripts|stylesheets)/ { root /home/deployer/shop/current/public;  expires max;  break;}

segunda-feira, 11 de abril de 2011

Turn on GZIP compression in your

proxy

segunda-feira, 11 de abril de 2011

Nginx config

gzip on;gzip_http_version 1.0;gzip_proxied any;gzip_min_length 500;gzip_disable "MSIE [1-6]\.";gzip_types text/html text/xml text/javascript;

segunda-feira, 11 de abril de 2011

CSS files should be at the beginning of your

page

segunda-feira, 11 de abril de 2011

Use CSS sprites

segunda-feira, 11 de abril de 2011

At the CSS CSS

<div  style="background-­‐image:  url('a_lot_of_sprites.gif');        background-­‐position:  -­‐260px  -­‐90px;        width:  26px;  height:  24px;"></div>

segunda-feira, 11 de abril de 2011

Get a CDN to serve your static assets and user generated content

CDN == Content Delivery NetworkS3, CloudFiles, Akamai, whatever...

segunda-feira, 11 de abril de 2011

Using Paperclip? has_attached_file :uploaded_data, :storage => :s3, :s3_credentials => "#{RAILS_ROOT}/config/s3.yml", :s3_headers => { "Expires" => "Thu, 31 Dec 2037 23:55:55 GMT", "Cache-Control" => "max-age=315360000" }, :path => "/:class/:attachment/:id/:style_:filename", :styles => { :thumb => '173x84#' }, :convert_options => { :all => '-strip' }

segunda-feira, 11 de abril de 2011

Merge all your CSS and JavaScript files in a single file for each

:cache => “all_styles”If you’re using Rails

segunda-feira, 11 de abril de 2011

Crush all your PNG filespngcrush for the win

segunda-feira, 11 de abril de 2011

Serve static assets from many different hosts

assets1.myblog.com.brassets2.myblog.com.brassets3.myblog.com.brassets4.myblog.com.br

segunda-feira, 11 de abril de 2011

Remove all metadata from your JPEGs

convert -strip source.jpeg destination.jpegImageMagick

segunda-feira, 11 de abril de 2011

JavaScript optimizations

segunda-feira, 11 de abril de 2011

Place scripts at the END of your page

segunda-feira, 11 de abril de 2011

Download script files asynchronously

document.write(“<script src=‘something.js’>”)

AJAX call then eval the body (RJS? Remember?)

dom.createElement( “script” )

segunda-feira, 11 de abril de 2011

Minify your Scripts

YUI Compressor

JSMIN

JS Minifier

segunda-feira, 11 de abril de 2011

Separate your scripts in MUST HAVE and CAN

WAITbeforeOnload.jsafterOnload.js

segunda-feira, 11 de abril de 2011

Use AJAX requests to navigate on your website

Twitter.com? That’s it!

segunda-feira, 11 de abril de 2011

Questions?Curses, compliments and money, now accepting all

credit cards

segunda-feira, 11 de abril de 2011