The document discusses various techniques for optimizing website performance, including respecting HTTP protocols like using GET requests for non-destructive actions; using a proxy server like Nginx to deliver static content; leveraging caching, compression, and content delivery networks; JavaScript and image optimizations; and asynchronous loading of scripts. The goal is to make websites faster by improving how static assets are served and how client-server interactions work.
Powerful Google developer tools for immediate impact! (2023-24 C)
The Fast, The Slow and the Lazy
1. The Fast, The Slow and
the Lazy
Maurício Linhares - @mauriciojr
http://techbot.me/
segunda-feira, 11 de abril de 2011
2. 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
4. Learn to respect the
HTTP protocol
What about reading the RFC?
segunda-feira, 11 de abril de 2011
5. A GET is, in fact, “GET a
COPY”
And copying should not change your database,
right?
segunda-feira, 11 de abril de 2011
6. 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
7. POST is SENDING stuff
to the server
And this would change your DATABASE
segunda-feira, 11 de abril de 2011
8. Idempotency principle
Many GETs == same result
Many POSTs == not necessarily the same result
segunda-feira, 11 de abril de 2011
9. Google Web Accelerator
An epic and dramatic story about how an #epic
#win becomes an #epic #fail
segunda-feira, 11 de abril de 2011
10. Front End Optimization
Easier than getting the Celtics to win an NBA
championship
segunda-feira, 11 de abril de 2011
11. Use a proxy server to
deliver your content
Nginx, please
!"#$%&' !"#$%&'' !"#$%&''
(' )' *'
!"#$%&
segunda-feira, 11 de abril de 2011
12. Define a far future
expires header for all of
your static assets
segunda-feira, 11 de abril de 2011
13. 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
14. Nginx config
location ~ ^/(images|javascripts|stylesheets)/ {
root /home/deployer/shop/current/public;
expires max;
break;
}
segunda-feira, 11 de abril de 2011
15. Turn on GZIP
compression in your
proxy
segunda-feira, 11 de abril de 2011
16. 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
17. CSS files should be at
the beginning of your
page
segunda-feira, 11 de abril de 2011
19. 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
20. Get a CDN to serve
your static assets and
user generated content
CDN == Content Delivery Network
S3, CloudFiles, Akamai, whatever...
segunda-feira, 11 de abril de 2011
21. 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
22. 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
23. Crush all your PNG files
pngcrush for the win
segunda-feira, 11 de abril de 2011
24. Serve static assets from
many different hosts
assets1.myblog.com.br
assets2.myblog.com.br
assets3.myblog.com.br
assets4.myblog.com.br
segunda-feira, 11 de abril de 2011
25. Remove all metadata
from your JPEGs
convert -strip source.jpeg destination.jpeg
ImageMagick
segunda-feira, 11 de abril de 2011
27. Place scripts at the END
of your page
segunda-feira, 11 de abril de 2011
28. 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
29. Minify your Scripts
YUI Compressor
JSMIN
JS Minifier
segunda-feira, 11 de abril de 2011
30. Separate your scripts in
MUST HAVE and CAN
WAIT
beforeOnload.js
afterOnload.js
segunda-feira, 11 de abril de 2011
31. Use AJAX requests to
navigate on your website
Twitter.com? That’s it!
segunda-feira, 11 de abril de 2011
32. Questions?
Curses, compliments and money, now accepting all
credit cards
segunda-feira, 11 de abril de 2011