SlideShare una empresa de Scribd logo
1 de 45
GETTING AN “A” IN YSLOW
                           Web Performance Optimization 101
                        Nick Zadrozny <nick@beyondthepath.com>




Friday, March 6, 2009
HI, MY NAME IS NICK.
                             I MAKE WEBSITES.




Friday, March 6, 2009
I’M EMBARRASSED
                          MY WEBSITES ARE SLOW




Friday, March 6, 2009
<METAPHOR>




Friday, March 6, 2009
You’re driving a brand new car
                   It’s moving really slowly

                   You can smell smoke

                   People are giving you looks




Friday, March 6, 2009
You’re driving a brand new car
                   It’s moving really slowly     Return the car

                   You can smell smoke           Rebuild the car

                   People are giving you looks   Disengage the hand brake




Friday, March 6, 2009
D’oh!




Friday, March 6, 2009
</METAPHOR>




Friday, March 6, 2009
THE POINT
                        LOW-HANGING FRUIT…




Friday, March 6, 2009
YAHOO!
                        THEY MAKE WEBSITES




Friday, March 6, 2009
Yahoo!
                        34 “Best Practices” for Exceptional Performance
              1. Minimize HTTP            9. Reduce DNS Lookups        19. Reduce the Number of   27. Choose <link> over
                 Requests                                                  DOM Elements               @import
                                          10. Minify JavaScript and
              2. Use a Content                CSS                      20. Split Components       28. Avoid Filters
                 Delivery Network                                          Across Domains
                                          11. Avoid Redirects                                     29. Optimize Images
              3. Add an Expires or a                                   21. Minimize the Number
                                          12. Remove Duplicate                                    30. Optimize CSS Sprites
                 Cache-Control                                             of iframes
                                              Scripts
                 Header                                                                           31. Don’t Scale Images in
                                                                       22. No 404s
                                          13. Configure ETags                                         HTML
              4. Gzip Components
                                                                       23. Reduce Cookie Size
                                          14. Make Ajax Cacheable                                 32. Make favicon.ico
              5. Put Stylesheets at the
                                                                       24. Use Cookie-free            Small and Cacheable
                 Top                      15. Flush the Buffer Early       Domains for
                                                                                                  33. Keep Components
              6. Put Scripts at the                                        Components
                                          16. Use GET for AJAX                                        under 25K (mobile)
                 Bottom                       Requests                 25. Minimize DOM
                                                                                                  34. Pack Components
              7. Avoid CSS                                                 Access
                                          17. Post-load                                               into a Multipart
                 Expressions                  Components               26. Develop Smart Event        Document (mobile)
              8. Make Javascript and                                       Handlers
                                          18. Preload Components
                 CSS External



Friday, March 6, 2009
YSLOW
                        PLUGIN FOR FIREBUG




Friday, March 6, 2009
YSlow
                                    Tests Your Site on 13 Rules

                   Minimize HTTP          Put Stylesheets at      Reduce DNS
                   Requests               the Top                 Lookups

                   Use a Content          Put Scripts at the      Minify JavaScript
                   Delivery Network       Bottom                  and CSS

                   Add an Expires         Avoid CSS               Avoid Redirects
                   or a Cache-            Expressions
                                                                  Remove
                   Control Header
                                          Make Javascript         Duplicate Scripts
                   Gzip                   and CSS External
                                                                  Configure ETags
                   Components

Friday, March 6, 2009
MINIMIZE HTTP REQUESTS




Friday, March 6, 2009
Minimize HTTP Requests

                         HTTP Requests are Expensive!
                         Net work latency + server latency + net work latency + download time.

                         This rule is fundamental, the Catch-All. Everything else is based on it.

                         Asset packaging reduces overall number of requests.

                         Compression & minification reduce the size of responses.

                         Reordering includes lets important stuff go first.

                         ETags and Last-Modified checks reduce the content of an HTTP Request.

                         Browser caching completely eliminates subsequent requests. Major win.




Friday, March 6, 2009
MAKE JAVASCRIPT
                        AND CSS EXTERNAL



Friday, March 6, 2009
Make Javascript
                                and CSS External
                   Easier to maintain, less HTML to send

                   Browser caching prevents later requests

                   Help order requests by priority

                   Rails makes this pretty easy,

                   stylesheet_link_tag
                   javascript_include_tag




Friday, March 6, 2009
MINIFY JAVASCRIPT
                             AND CSS



Friday, March 6, 2009
Minify Javascript and CSS

                   ≈20% size reduction         html,body,div,span,applet,object,iframe,h1,h2
                                               ,h3,h4,h5,h6,p,blockquote,pre,a,abbr,acronym,
                                               address,big,cite,code,del,dfn,em,font,img,ins

                   Using a framework? You’re   ,kbd,q,s,samp,small,strike,strong,sub,sup,tt,
                                               var,b,u,i,center,dl,dt,dd,ol,ul,li,fieldset,f
                                               orm,label,legend,table,caption,tbody,tfoot,th
                   probably halfway there.     ead,tr,th,td{margin:0;padding:0;border:
                                               0;outline:0;font-size:100%;vertical-
                                               align:baseline;background:transparent}
                                               body{line-height:1}ol,ul{list-style:none}

                   YUI Compressor + Rake       blockquote,q{quotes:none}blockquote:before,bl
                                               ockquote:after,q:before,q:after{content:'';co
                                               ntent:none}:focus{outline:0}ins{text-
                                               decoration:none}del{text-decoration:line-
                                               through}table{border-collapse:collapse;
                                               border-spacing:0}




Friday, March 6, 2009
STYLESHEETS AT THE TOP
                  SCRIPTS AT THE BOTTOM



Friday, March 6, 2009
Stylesheets at the top
                             Scripts at the bottom
                                                  <!DOCTYPE html>

                   Javascript shouldn’t block     <html>
                                                    <head>

                   more important rendering
                                                      <title>Your Awesome Site</title>
                                                      <%= stylesheet_link_tag 'application' %>
                                                      <%= yield(:head) %>
                                                    </head>
                                                    <body>
                   Pass blocks to the head and        <div id=quot;pagequot;>
                                                         <header>

                   foot from within your views:            <h1>Awesome Site</h1>
                                                         </header>
                                                         <article>
                                                           <%= yield %>
                   <% content_for(:foot) do %>           </article>
                     <%= javascript_tag quot;…quot; %>        </div>
                                                      <%= javascript_include_tag 'application' %>
                   <% end %>                          <%= yield(:foot) %>
                                                    </body>
                                                  </html>




Friday, March 6, 2009
GZIP COMPONENTS




Friday, March 6, 2009
GZip Components
                   Another nice size reduction

                   Most devices support it

                   CSS, Javascript, text/html,
                   text/plain




Friday, March 6, 2009
SOME REALLY EASY ONES…




Friday, March 6, 2009
AVOID CSS EXPRESSIONS




Friday, March 6, 2009
AVOID REDIRECTS




Friday, March 6, 2009
REMOVE DUPLICATE
                            SCRIPTS



Friday, March 6, 2009
REDUCE DNS LOOKUPS




Friday, March 6, 2009
Apache gives this for free for most of your
                        assets.

                        Rails gives this for free for all of the
                        responses it sends back. It also has some
                        helpers that will let you potentially skip db
                        calls and expensive view rendering.




                                      CONFIGURE ETAGS




Friday, March 6, 2009
Configure ETags

                   Web servers likely give you a lot for free

                   Rails gives you some ETagging for free

                   Rails ETag and Last-Modified helper
                   def show
                     @article = Article.find(params[:id])

                     if stale?(:etag => @article, :last_modified => @article.created_at.utc)
                       @statistics = @article.really_expensive_call
                       respond_to do |format|
                         # etc
                       end
                     end
                   end




Friday, March 6, 2009
ADD AN EXPIRES OR
                CACHE-CONTROL HEADER



Friday, March 6, 2009
Add an Expires Header

                   Check out mod_expires for Apache

                   Rails already does “soft” cache busting

                   Hard cache busting (for CDNs)…

                   config.action_controller.asset_host =
                   quot;http://assets.example.com/#{REVISION}quot;




Friday, March 6, 2009
USE A CDN




Friday, March 6, 2009
#!/usr/bin/env ruby
      require File.dirname(__FILE__) + '/../config/environment'

      require 'aws/s3'
      require 'progressbar'

      # Set up the S3 configuration and connection
      config = YAML.load(File.open(File.join(RAILS_ROOT, 'config/amazon_s3.yml')))[RAILS_ENV]
      bucket = config['bucket_name']
      AWS::S3::Base.establish_connection!(
        :access_key_id     => config['access_key_id'],
        :secret_access_key => config['secret_access_key']
      )

      # Grab everything in the public directory
      files = Dir.glob(File.join(RAILS_ROOT, 'public/**/*/**/*.{css,js,gif,jpg,png,…}'))

      # Set up the progressbar
      progressbar = ProgressBar.new(quot;Uploading...quot;, files.size)

      # Iterate through the files
      files.each do |file|

         # Skip directories themselves - we're only interested in files
         unless File.directory?(file)

           # Create an object key from the file name and revision
           key = file.gsub(/.*public//,quot;#{REVISION}/quot;)

           # Upload the object to S3
           # TODO: make sure we're setting the right headers for gzipped objects
           AWS::S3::S3Object.store(
             key, open(file), bucket,
             :access => :public_read, :expires => 1.year.from_now
           )

           # Increment the progressbar
           progressbar.inc

        end
      end



Friday, March 6, 2009
#!/usr/bin/env ruby
      require File.dirname(__FILE__) + '/../config/environment'

      require 'aws/s3'
      require 'progressbar'
      # Set up the S3 configuration and connection
      config = YAML.load(File.open(File.join(RAILS_ROOT, 'config/amazon_s3.yml')))[RAILS_ENV]
      bucket = config['bucket_name']
      AWS::S3::Base.establish_connection!(
        :access_key_id     => config['access_key_id'],
        :secret_access_key => config['secret_access_key']
      )

      # Grab everything in the public directory
      files = Dir.glob(File.join(RAILS_ROOT, 'public/**/*/**/*.{css,js,gif,jpg,png,…}'))

      # Set up the progressbar
      progressbar = ProgressBar.new(quot;Uploading...quot;, files.size)

      # Iterate through the files
      files.each do |file|

        # Skip directories themselves - we're only interested in files
        unless File.directory?(file)

          # Create an object key from the file name and revision
          key = file.gsub(/.*public//,quot;#{REVISION}/quot;)

          # Upload the object to S3
          # TODO: make sure we're setting the right headers for gzipped objects
          AWS::S3::S3Object.store(
            key, open(file), bucket,
            :access => :public_read, :expires => 1.year.from_now
          )

          # Increment the progressbar
          progressbar.inc

        end
      end




Friday, March 6, 2009
#!/usr/bin/env ruby
      require File.dirname(__FILE__) + '/../config/environment'

      require 'aws/s3'
      require 'progressbar'


      # Set up the S3 configuration and connection
      config = YAML.load(File.open(File.join(RAILS_ROOT, 'config/amazon_s3.yml')))[RAILS_ENV]
      bucket = config['bucket_name']
      AWS::S3::Base.establish_connection!(
        :access_key_id     => config['access_key_id'],
        :secret_access_key => config['secret_access_key']
      )
      # Grab everything in the public directory
      files = Dir.glob(File.join(RAILS_ROOT, 'public/**/*/**/*.{css,js,gif,jpg,png,…}'))

      # Set up the progressbar
      progressbar = ProgressBar.new(quot;Uploading...quot;, files.size)

      # Iterate through the files
      files.each do |file|

        # Skip directories themselves - we're only interested in files
        unless File.directory?(file)

          # Create an object key from the file name and revision
          key = file.gsub(/.*public//,quot;#{REVISION}/quot;)

          # Upload the object to S3
          # TODO: make sure we're setting the right headers for gzipped objects
          AWS::S3::S3Object.store(
            key, open(file), bucket,
            :access => :public_read, :expires => 1.year.from_now
          )

          # Increment the progressbar
          progressbar.inc

        end
      end




Friday, March 6, 2009
#!/usr/bin/env ruby
      require File.dirname(__FILE__) + '/../config/environment'

      require 'aws/s3'
      require 'progressbar'

      # Set up the S3 configuration and connection
      config = YAML.load(File.open(File.join(RAILS_ROOT, 'config/amazon_s3.yml')))[RAILS_ENV]
      bucket = config['bucket_name']
      AWS::S3::Base.establish_connection!(
        :access_key_id     => config['access_key_id'],
        :secret_access_key => config['secret_access_key']
      )


      # Grab everything in the public directory
      files = Dir.glob(File.join(RAILS_ROOT, 'public/**/*/**/*.{css,js,gif,jpg,png,…}'))

      # Set up the progressbar
      progressbar = ProgressBar.new(quot;Uploading...quot;, files.size)
      # Iterate through the files
      files.each do |file|

        # Skip directories themselves - we're only interested in files
        unless File.directory?(file)

          # Create an object key from the file name and revision
          key = file.gsub(/.*public//,quot;#{REVISION}/quot;)

          # Upload the object to S3
          # TODO: make sure we're setting the right headers for gzipped objects
          AWS::S3::S3Object.store(
            key, open(file), bucket,
            :access => :public_read, :expires => 1.year.from_now
          )

          # Increment the progressbar
          progressbar.inc

        end
      end




Friday, March 6, 2009
#!/usr/bin/env ruby
      require File.dirname(__FILE__) + '/../config/environment'

      require 'aws/s3'
      require 'progressbar'

      # Set up the S3 configuration and connection
      config = YAML.load(File.open(File.join(RAILS_ROOT, 'config/amazon_s3.yml')))[RAILS_ENV]
      bucket = config['bucket_name']
      AWS::S3::Base.establish_connection!(
        :access_key_id     => config['access_key_id'],
        :secret_access_key => config['secret_access_key']
      )

      # Grab everything in the public directory
      files = Dir.glob(File.join(RAILS_ROOT, 'public/**/*/**/*.{css,js,gif,jpg,png,…}'))

      # Set up the progressbar
      progressbar = ProgressBar.new(quot;Uploading...quot;, files.size)


      # Iterate through the files
      files.each do |file|
        # Skip directories themselves - we're only interested in files
        unless File.directory?(file)

          # Create an object key from the file name and revision
          key = file.gsub(/.*public//,quot;#{REVISION}/quot;)

          # Upload the object to S3
          # TODO: make sure we're setting the right headers for gzipped objects
          AWS::S3::S3Object.store(
            key, open(file), bucket,
            :access => :public_read, :expires => 1.year.from_now
          )

          # Increment the progressbar
          progressbar.inc

        end
      end




Friday, March 6, 2009
#!/usr/bin/env ruby
      require File.dirname(__FILE__) + '/../config/environment'

      require 'aws/s3'
      require 'progressbar'

      # Set up the S3 configuration and connection
      config = YAML.load(File.open(File.join(RAILS_ROOT, 'config/amazon_s3.yml')))[RAILS_ENV]
      bucket = config['bucket_name']
      AWS::S3::Base.establish_connection!(
        :access_key_id     => config['access_key_id'],
        :secret_access_key => config['secret_access_key']
      )

      # Grab everything in the public directory
      files = Dir.glob(File.join(RAILS_ROOT, 'public/**/*/**/*.{css,js,gif,jpg,png,…}'))

      # Set up the progressbar
      progressbar = ProgressBar.new(quot;Uploading...quot;, files.size)

      # Iterate through the files
      files.each do |file|


          # Skip directories themselves - we're only interested in files
          unless File.directory?(file)
          # Create an object key from the file name and revision
          key = file.gsub(/.*public//,quot;#{REVISION}/quot;)

          # Upload the object to S3
          # TODO: make sure we're setting the right headers for gzipped objects
          AWS::S3::S3Object.store(
            key, open(file), bucket,
            :access => :public_read, :expires => 1.year.from_now
          )

          # Increment the progressbar
          progressbar.inc

        end
      end




Friday, March 6, 2009
#!/usr/bin/env ruby
      require File.dirname(__FILE__) + '/../config/environment'

      require 'aws/s3'
      require 'progressbar'

      # Set up the S3 configuration and connection
      config = YAML.load(File.open(File.join(RAILS_ROOT, 'config/amazon_s3.yml')))[RAILS_ENV]
      bucket = config['bucket_name']
      AWS::S3::Base.establish_connection!(
        :access_key_id     => config['access_key_id'],
        :secret_access_key => config['secret_access_key']
      )

      # Grab everything in the public directory
      files = Dir.glob(File.join(RAILS_ROOT, 'public/**/*/**/*.{css,js,gif,jpg,png,…}'))

      # Set up the progressbar
      progressbar = ProgressBar.new(quot;Uploading...quot;, files.size)

      # Iterate through the files
      files.each do |file|

        # Skip directories themselves - we're only interested in files
        unless File.directory?(file)


              # Create an object key from the file name and revision
              key = file.gsub(/.*public//,quot;#{REVISION}/quot;)
          # Upload the object to S3
          # TODO: make sure we're setting the right headers for gzipped objects
          AWS::S3::S3Object.store(
            key, open(file), bucket,
            :access => :public_read, :expires => 1.year.from_now
          )

          # Increment the progressbar
          progressbar.inc

        end
      end




Friday, March 6, 2009
#!/usr/bin/env ruby
      require File.dirname(__FILE__) + '/../config/environment'

      require 'aws/s3'
      require 'progressbar'

      # Set up the S3 configuration and connection
      config = YAML.load(File.open(File.join(RAILS_ROOT, 'config/amazon_s3.yml')))[RAILS_ENV]
      bucket = config['bucket_name']
      AWS::S3::Base.establish_connection!(
        :access_key_id     => config['access_key_id'],
        :secret_access_key => config['secret_access_key']
      )

      # Grab everything in the public directory
      files = Dir.glob(File.join(RAILS_ROOT, 'public/**/*/**/*.{css,js,gif,jpg,png,…}'))

      # Set up the progressbar
      progressbar = ProgressBar.new(quot;Uploading...quot;, files.size)

      # Iterate through the files
      files.each do |file|

        # Skip directories themselves - we're only interested in files
        unless File.directory?(file)

          # Create an object key from the file name and revision
          key = file.gsub(/.*public//,quot;#{REVISION}/quot;)


              # Upload the object to S3
              # TODO: set the right headers for gzipped objects
              AWS::S3::S3Object.store(
                key, open(file), bucket,
                :access => :public_read, :expires => 1.year.from_now
              )
          # Increment the progressbar
          progressbar.inc

        end
      end




Friday, March 6, 2009
#!/usr/bin/env ruby
      require File.dirname(__FILE__) + '/../config/environment'

      require 'aws/s3'
      require 'progressbar'

      # Set up the S3 configuration and connection
      config = YAML.load(File.open(File.join(RAILS_ROOT, 'config/amazon_s3.yml')))[RAILS_ENV]
      bucket = config['bucket_name']
      AWS::S3::Base.establish_connection!(
        :access_key_id     => config['access_key_id'],
        :secret_access_key => config['secret_access_key']
      )

      # Grab everything in the public directory
      files = Dir.glob(File.join(RAILS_ROOT, 'public/**/*/**/*.{css,js,gif,jpg,png,…}'))

      # Set up the progressbar
      progressbar = ProgressBar.new(quot;Uploading...quot;, files.size)

      # Iterate through the files
      files.each do |file|

         # Skip directories themselves - we're only interested in files
         unless File.directory?(file)

           # Create an object key from the file name and revision
           key = file.gsub(/.*public//,quot;#{REVISION}/quot;)

           # Upload the object to S3
           # TODO: make sure we're setting the right headers for gzipped objects
           AWS::S3::S3Object.store(
             key, open(file), bucket,
             :access => :public_read, :expires => 1.year.from_now
           )

           # Increment the progressbar
           progressbar.inc

        end
      end



Friday, March 6, 2009
THAT’S IT!




Friday, March 6, 2009
Friday, March 6, 2009
ARTICLE FORTHCOMING
                          BEYOND THE PATH.COM




Friday, March 6, 2009

Más contenido relacionado

Último

The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionDilum Bandara
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embeddingZilliz
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfMounikaPolabathina
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESmohitsingh558521
 
What is Artificial Intelligence?????????
What is Artificial Intelligence?????????What is Artificial Intelligence?????????
What is Artificial Intelligence?????????blackmambaettijean
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningLars Bell
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rick Flair
 

Último (20)

The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embedding
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdf
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
 
What is Artificial Intelligence?????????
What is Artificial Intelligence?????????What is Artificial Intelligence?????????
What is Artificial Intelligence?????????
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...
 

Destacado

Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsPixeldarts
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthThinkNow
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfmarketingartwork
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Applitools
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at WorkGetSmarter
 

Destacado (20)

Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work
 

Earning An "A" In YSlow – SDRuby 2009-03-05

  • 1. GETTING AN “A” IN YSLOW Web Performance Optimization 101 Nick Zadrozny <nick@beyondthepath.com> Friday, March 6, 2009
  • 2. HI, MY NAME IS NICK. I MAKE WEBSITES. Friday, March 6, 2009
  • 3. I’M EMBARRASSED MY WEBSITES ARE SLOW Friday, March 6, 2009
  • 5. You’re driving a brand new car It’s moving really slowly You can smell smoke People are giving you looks Friday, March 6, 2009
  • 6. You’re driving a brand new car It’s moving really slowly Return the car You can smell smoke Rebuild the car People are giving you looks Disengage the hand brake Friday, March 6, 2009
  • 9. THE POINT LOW-HANGING FRUIT… Friday, March 6, 2009
  • 10. YAHOO! THEY MAKE WEBSITES Friday, March 6, 2009
  • 11. Yahoo! 34 “Best Practices” for Exceptional Performance 1. Minimize HTTP 9. Reduce DNS Lookups 19. Reduce the Number of 27. Choose <link> over Requests DOM Elements @import 10. Minify JavaScript and 2. Use a Content CSS 20. Split Components 28. Avoid Filters Delivery Network Across Domains 11. Avoid Redirects 29. Optimize Images 3. Add an Expires or a 21. Minimize the Number 12. Remove Duplicate 30. Optimize CSS Sprites Cache-Control of iframes Scripts Header 31. Don’t Scale Images in 22. No 404s 13. Configure ETags HTML 4. Gzip Components 23. Reduce Cookie Size 14. Make Ajax Cacheable 32. Make favicon.ico 5. Put Stylesheets at the 24. Use Cookie-free Small and Cacheable Top 15. Flush the Buffer Early Domains for 33. Keep Components 6. Put Scripts at the Components 16. Use GET for AJAX under 25K (mobile) Bottom Requests 25. Minimize DOM 34. Pack Components 7. Avoid CSS Access 17. Post-load into a Multipart Expressions Components 26. Develop Smart Event Document (mobile) 8. Make Javascript and Handlers 18. Preload Components CSS External Friday, March 6, 2009
  • 12. YSLOW PLUGIN FOR FIREBUG Friday, March 6, 2009
  • 13. YSlow Tests Your Site on 13 Rules Minimize HTTP Put Stylesheets at Reduce DNS Requests the Top Lookups Use a Content Put Scripts at the Minify JavaScript Delivery Network Bottom and CSS Add an Expires Avoid CSS Avoid Redirects or a Cache- Expressions Remove Control Header Make Javascript Duplicate Scripts Gzip and CSS External Configure ETags Components Friday, March 6, 2009
  • 15. Minimize HTTP Requests HTTP Requests are Expensive! Net work latency + server latency + net work latency + download time. This rule is fundamental, the Catch-All. Everything else is based on it. Asset packaging reduces overall number of requests. Compression & minification reduce the size of responses. Reordering includes lets important stuff go first. ETags and Last-Modified checks reduce the content of an HTTP Request. Browser caching completely eliminates subsequent requests. Major win. Friday, March 6, 2009
  • 16. MAKE JAVASCRIPT AND CSS EXTERNAL Friday, March 6, 2009
  • 17. Make Javascript and CSS External Easier to maintain, less HTML to send Browser caching prevents later requests Help order requests by priority Rails makes this pretty easy, stylesheet_link_tag javascript_include_tag Friday, March 6, 2009
  • 18. MINIFY JAVASCRIPT AND CSS Friday, March 6, 2009
  • 19. Minify Javascript and CSS ≈20% size reduction html,body,div,span,applet,object,iframe,h1,h2 ,h3,h4,h5,h6,p,blockquote,pre,a,abbr,acronym, address,big,cite,code,del,dfn,em,font,img,ins Using a framework? You’re ,kbd,q,s,samp,small,strike,strong,sub,sup,tt, var,b,u,i,center,dl,dt,dd,ol,ul,li,fieldset,f orm,label,legend,table,caption,tbody,tfoot,th probably halfway there. ead,tr,th,td{margin:0;padding:0;border: 0;outline:0;font-size:100%;vertical- align:baseline;background:transparent} body{line-height:1}ol,ul{list-style:none} YUI Compressor + Rake blockquote,q{quotes:none}blockquote:before,bl ockquote:after,q:before,q:after{content:'';co ntent:none}:focus{outline:0}ins{text- decoration:none}del{text-decoration:line- through}table{border-collapse:collapse; border-spacing:0} Friday, March 6, 2009
  • 20. STYLESHEETS AT THE TOP SCRIPTS AT THE BOTTOM Friday, March 6, 2009
  • 21. Stylesheets at the top Scripts at the bottom <!DOCTYPE html> Javascript shouldn’t block <html> <head> more important rendering <title>Your Awesome Site</title> <%= stylesheet_link_tag 'application' %> <%= yield(:head) %> </head> <body> Pass blocks to the head and <div id=quot;pagequot;> <header> foot from within your views: <h1>Awesome Site</h1> </header> <article> <%= yield %> <% content_for(:foot) do %> </article> <%= javascript_tag quot;…quot; %> </div> <%= javascript_include_tag 'application' %> <% end %> <%= yield(:foot) %> </body> </html> Friday, March 6, 2009
  • 23. GZip Components Another nice size reduction Most devices support it CSS, Javascript, text/html, text/plain Friday, March 6, 2009
  • 24. SOME REALLY EASY ONES… Friday, March 6, 2009
  • 27. REMOVE DUPLICATE SCRIPTS Friday, March 6, 2009
  • 28. REDUCE DNS LOOKUPS Friday, March 6, 2009
  • 29. Apache gives this for free for most of your assets. Rails gives this for free for all of the responses it sends back. It also has some helpers that will let you potentially skip db calls and expensive view rendering. CONFIGURE ETAGS Friday, March 6, 2009
  • 30. Configure ETags Web servers likely give you a lot for free Rails gives you some ETagging for free Rails ETag and Last-Modified helper def show @article = Article.find(params[:id]) if stale?(:etag => @article, :last_modified => @article.created_at.utc) @statistics = @article.really_expensive_call respond_to do |format| # etc end end end Friday, March 6, 2009
  • 31. ADD AN EXPIRES OR CACHE-CONTROL HEADER Friday, March 6, 2009
  • 32. Add an Expires Header Check out mod_expires for Apache Rails already does “soft” cache busting Hard cache busting (for CDNs)… config.action_controller.asset_host = quot;http://assets.example.com/#{REVISION}quot; Friday, March 6, 2009
  • 33. USE A CDN Friday, March 6, 2009
  • 34. #!/usr/bin/env ruby require File.dirname(__FILE__) + '/../config/environment' require 'aws/s3' require 'progressbar' # Set up the S3 configuration and connection config = YAML.load(File.open(File.join(RAILS_ROOT, 'config/amazon_s3.yml')))[RAILS_ENV] bucket = config['bucket_name'] AWS::S3::Base.establish_connection!( :access_key_id => config['access_key_id'], :secret_access_key => config['secret_access_key'] ) # Grab everything in the public directory files = Dir.glob(File.join(RAILS_ROOT, 'public/**/*/**/*.{css,js,gif,jpg,png,…}')) # Set up the progressbar progressbar = ProgressBar.new(quot;Uploading...quot;, files.size) # Iterate through the files files.each do |file| # Skip directories themselves - we're only interested in files unless File.directory?(file) # Create an object key from the file name and revision key = file.gsub(/.*public//,quot;#{REVISION}/quot;) # Upload the object to S3 # TODO: make sure we're setting the right headers for gzipped objects AWS::S3::S3Object.store( key, open(file), bucket, :access => :public_read, :expires => 1.year.from_now ) # Increment the progressbar progressbar.inc end end Friday, March 6, 2009
  • 35. #!/usr/bin/env ruby require File.dirname(__FILE__) + '/../config/environment' require 'aws/s3' require 'progressbar' # Set up the S3 configuration and connection config = YAML.load(File.open(File.join(RAILS_ROOT, 'config/amazon_s3.yml')))[RAILS_ENV] bucket = config['bucket_name'] AWS::S3::Base.establish_connection!( :access_key_id => config['access_key_id'], :secret_access_key => config['secret_access_key'] ) # Grab everything in the public directory files = Dir.glob(File.join(RAILS_ROOT, 'public/**/*/**/*.{css,js,gif,jpg,png,…}')) # Set up the progressbar progressbar = ProgressBar.new(quot;Uploading...quot;, files.size) # Iterate through the files files.each do |file| # Skip directories themselves - we're only interested in files unless File.directory?(file) # Create an object key from the file name and revision key = file.gsub(/.*public//,quot;#{REVISION}/quot;) # Upload the object to S3 # TODO: make sure we're setting the right headers for gzipped objects AWS::S3::S3Object.store( key, open(file), bucket, :access => :public_read, :expires => 1.year.from_now ) # Increment the progressbar progressbar.inc end end Friday, March 6, 2009
  • 36. #!/usr/bin/env ruby require File.dirname(__FILE__) + '/../config/environment' require 'aws/s3' require 'progressbar' # Set up the S3 configuration and connection config = YAML.load(File.open(File.join(RAILS_ROOT, 'config/amazon_s3.yml')))[RAILS_ENV] bucket = config['bucket_name'] AWS::S3::Base.establish_connection!( :access_key_id => config['access_key_id'], :secret_access_key => config['secret_access_key'] ) # Grab everything in the public directory files = Dir.glob(File.join(RAILS_ROOT, 'public/**/*/**/*.{css,js,gif,jpg,png,…}')) # Set up the progressbar progressbar = ProgressBar.new(quot;Uploading...quot;, files.size) # Iterate through the files files.each do |file| # Skip directories themselves - we're only interested in files unless File.directory?(file) # Create an object key from the file name and revision key = file.gsub(/.*public//,quot;#{REVISION}/quot;) # Upload the object to S3 # TODO: make sure we're setting the right headers for gzipped objects AWS::S3::S3Object.store( key, open(file), bucket, :access => :public_read, :expires => 1.year.from_now ) # Increment the progressbar progressbar.inc end end Friday, March 6, 2009
  • 37. #!/usr/bin/env ruby require File.dirname(__FILE__) + '/../config/environment' require 'aws/s3' require 'progressbar' # Set up the S3 configuration and connection config = YAML.load(File.open(File.join(RAILS_ROOT, 'config/amazon_s3.yml')))[RAILS_ENV] bucket = config['bucket_name'] AWS::S3::Base.establish_connection!( :access_key_id => config['access_key_id'], :secret_access_key => config['secret_access_key'] ) # Grab everything in the public directory files = Dir.glob(File.join(RAILS_ROOT, 'public/**/*/**/*.{css,js,gif,jpg,png,…}')) # Set up the progressbar progressbar = ProgressBar.new(quot;Uploading...quot;, files.size) # Iterate through the files files.each do |file| # Skip directories themselves - we're only interested in files unless File.directory?(file) # Create an object key from the file name and revision key = file.gsub(/.*public//,quot;#{REVISION}/quot;) # Upload the object to S3 # TODO: make sure we're setting the right headers for gzipped objects AWS::S3::S3Object.store( key, open(file), bucket, :access => :public_read, :expires => 1.year.from_now ) # Increment the progressbar progressbar.inc end end Friday, March 6, 2009
  • 38. #!/usr/bin/env ruby require File.dirname(__FILE__) + '/../config/environment' require 'aws/s3' require 'progressbar' # Set up the S3 configuration and connection config = YAML.load(File.open(File.join(RAILS_ROOT, 'config/amazon_s3.yml')))[RAILS_ENV] bucket = config['bucket_name'] AWS::S3::Base.establish_connection!( :access_key_id => config['access_key_id'], :secret_access_key => config['secret_access_key'] ) # Grab everything in the public directory files = Dir.glob(File.join(RAILS_ROOT, 'public/**/*/**/*.{css,js,gif,jpg,png,…}')) # Set up the progressbar progressbar = ProgressBar.new(quot;Uploading...quot;, files.size) # Iterate through the files files.each do |file| # Skip directories themselves - we're only interested in files unless File.directory?(file) # Create an object key from the file name and revision key = file.gsub(/.*public//,quot;#{REVISION}/quot;) # Upload the object to S3 # TODO: make sure we're setting the right headers for gzipped objects AWS::S3::S3Object.store( key, open(file), bucket, :access => :public_read, :expires => 1.year.from_now ) # Increment the progressbar progressbar.inc end end Friday, March 6, 2009
  • 39. #!/usr/bin/env ruby require File.dirname(__FILE__) + '/../config/environment' require 'aws/s3' require 'progressbar' # Set up the S3 configuration and connection config = YAML.load(File.open(File.join(RAILS_ROOT, 'config/amazon_s3.yml')))[RAILS_ENV] bucket = config['bucket_name'] AWS::S3::Base.establish_connection!( :access_key_id => config['access_key_id'], :secret_access_key => config['secret_access_key'] ) # Grab everything in the public directory files = Dir.glob(File.join(RAILS_ROOT, 'public/**/*/**/*.{css,js,gif,jpg,png,…}')) # Set up the progressbar progressbar = ProgressBar.new(quot;Uploading...quot;, files.size) # Iterate through the files files.each do |file| # Skip directories themselves - we're only interested in files unless File.directory?(file) # Create an object key from the file name and revision key = file.gsub(/.*public//,quot;#{REVISION}/quot;) # Upload the object to S3 # TODO: make sure we're setting the right headers for gzipped objects AWS::S3::S3Object.store( key, open(file), bucket, :access => :public_read, :expires => 1.year.from_now ) # Increment the progressbar progressbar.inc end end Friday, March 6, 2009
  • 40. #!/usr/bin/env ruby require File.dirname(__FILE__) + '/../config/environment' require 'aws/s3' require 'progressbar' # Set up the S3 configuration and connection config = YAML.load(File.open(File.join(RAILS_ROOT, 'config/amazon_s3.yml')))[RAILS_ENV] bucket = config['bucket_name'] AWS::S3::Base.establish_connection!( :access_key_id => config['access_key_id'], :secret_access_key => config['secret_access_key'] ) # Grab everything in the public directory files = Dir.glob(File.join(RAILS_ROOT, 'public/**/*/**/*.{css,js,gif,jpg,png,…}')) # Set up the progressbar progressbar = ProgressBar.new(quot;Uploading...quot;, files.size) # Iterate through the files files.each do |file| # Skip directories themselves - we're only interested in files unless File.directory?(file) # Create an object key from the file name and revision key = file.gsub(/.*public//,quot;#{REVISION}/quot;) # Upload the object to S3 # TODO: make sure we're setting the right headers for gzipped objects AWS::S3::S3Object.store( key, open(file), bucket, :access => :public_read, :expires => 1.year.from_now ) # Increment the progressbar progressbar.inc end end Friday, March 6, 2009
  • 41. #!/usr/bin/env ruby require File.dirname(__FILE__) + '/../config/environment' require 'aws/s3' require 'progressbar' # Set up the S3 configuration and connection config = YAML.load(File.open(File.join(RAILS_ROOT, 'config/amazon_s3.yml')))[RAILS_ENV] bucket = config['bucket_name'] AWS::S3::Base.establish_connection!( :access_key_id => config['access_key_id'], :secret_access_key => config['secret_access_key'] ) # Grab everything in the public directory files = Dir.glob(File.join(RAILS_ROOT, 'public/**/*/**/*.{css,js,gif,jpg,png,…}')) # Set up the progressbar progressbar = ProgressBar.new(quot;Uploading...quot;, files.size) # Iterate through the files files.each do |file| # Skip directories themselves - we're only interested in files unless File.directory?(file) # Create an object key from the file name and revision key = file.gsub(/.*public//,quot;#{REVISION}/quot;) # Upload the object to S3 # TODO: set the right headers for gzipped objects AWS::S3::S3Object.store( key, open(file), bucket, :access => :public_read, :expires => 1.year.from_now ) # Increment the progressbar progressbar.inc end end Friday, March 6, 2009
  • 42. #!/usr/bin/env ruby require File.dirname(__FILE__) + '/../config/environment' require 'aws/s3' require 'progressbar' # Set up the S3 configuration and connection config = YAML.load(File.open(File.join(RAILS_ROOT, 'config/amazon_s3.yml')))[RAILS_ENV] bucket = config['bucket_name'] AWS::S3::Base.establish_connection!( :access_key_id => config['access_key_id'], :secret_access_key => config['secret_access_key'] ) # Grab everything in the public directory files = Dir.glob(File.join(RAILS_ROOT, 'public/**/*/**/*.{css,js,gif,jpg,png,…}')) # Set up the progressbar progressbar = ProgressBar.new(quot;Uploading...quot;, files.size) # Iterate through the files files.each do |file| # Skip directories themselves - we're only interested in files unless File.directory?(file) # Create an object key from the file name and revision key = file.gsub(/.*public//,quot;#{REVISION}/quot;) # Upload the object to S3 # TODO: make sure we're setting the right headers for gzipped objects AWS::S3::S3Object.store( key, open(file), bucket, :access => :public_read, :expires => 1.year.from_now ) # Increment the progressbar progressbar.inc end end Friday, March 6, 2009
  • 45. ARTICLE FORTHCOMING BEYOND THE PATH.COM Friday, March 6, 2009

Notas del editor