Code Monkey home page Code Monkey logo

grunt-sitespeedio's Introduction

grunt-sitespeedio

Test your website using sitespeed.io

grunt-sitespeedio is a Grunt.js task for testing your site against web performance best practice rules, fetch timings from a browser, test and enforce performance budgets, send performance metrics to Graphite using sitespeed.io.

Check out the documentation to get a full overview of what you can do and test using sitespeed.io.

Getting Started

This plugin requires Grunt ~0.4.5

If you haven't used Grunt before, be sure to check out the Getting Started guide, as it explains how to create a Gruntfile as well as install and use Grunt plugins. Once you're familiar with that process, you may install this plugin with this command:

npm install grunt-sitespeedio --save-dev

Once the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript:

grunt.loadNpmTasks('grunt-sitespeedio');

The sitespeedio task

Required configuration properties

To start testing pages, you must configure a URL for your crawl.

sitespeedio: {
  default: {
    options: {
      urls: ['https://www.sitespeed.io/']
    }
  }
}

Testing multiple URLs

sitespeedio: {
  default: {
    options: {
      urls: ['https://www.sitespeed.io', 'https://www.sitespeed.io/faq/']
    }
  }
}

With these configuration properties set, you can add sitespeedio to your default tasks list. That'll look something like this:

grunt.registerTask('default', ['jshint', 'sitespeedio']);

With this in place, grunt-sitespeedio will now collect performance metrics for your site.

The result files

The result files will automatically be stored in a temporary directory. If you want to change that, use the resultBaseDir property, like this:

sitespeedio: {
  default: {
    options: {
      urls: ['https://www.sitespeed.io'],
      outputFolder: '/my/new/dir/'
    }
  }
}

Use cases

Fetch timings, sending performance metrics to Graphite and performance budgets.

Fetching timing metrics

You can choose to collect Navigation Timing and User Timing metrics using real browser. You can choose by using Firefox or Chrome. And you can configure the connection speed (more info by choosing between mobile3g, mobile3gfast, cable and native. And choose how many times you want to test each URL (default is 3).

You surely want to combine it with running Xvfb to avoid opening the browser.

sitespeedio: {
  default: {
    options: {
      urls: ['https://www.sitespeed.io', 'https://www.sitespeed.io/faq/'],
      browsertime: {
        browser: 'firefox'
        connectivity: 'cable',
        iterations: 5,
      }
    }
  }
}

Performance Budget

Test your site against a performance budget. You can test your site against almost all data collected by sitespeed.io.

Checkout the example Gruntfile and budget looks something like this:

budget: {
  "browsertime.pageSummary": [{
    metric: "statistics.timings.firstPaint.median",
    "max": 1000
  }, {
    "metric": "statistics.visualMetrics.FirstVisualChange.median",
    "max": 1000
  }],
  "coach.pageSummary": [{
    "metric": "advice.performance.score",
    "min": 75
  }, {
    "metric": "advice.info.domElements",
    "max": 200
  }, {
    "metric": "advice.info.domDepth.max",
    "max": 10
  }, {
    "metric": "advice.info.iframes",
    "max": 0
  }, {
    "metric": "advice.info.pageCookies.max",
    "max": 5
  }],
  "pagexray.pageSummary": [{
    "metric": "transferSize",
    "max": 100000
  }, {
    "metric": "requests",
    "max": 20
  }, {
    "metric": "missingCompression",
    "max": 0
  }, {
    "metric": "contentTypes.css.requests",
    "max": 1
  }, {
    "metric": "contentTypes.image.transferSize",
    "max": 100000
  }, {
    "metric": "documentRedirects",
    "max": 0
  }]

If you want to include/exclude tests in the output, you can switch that by a Grunt config like:

grunt.config.set('includePassed', true);

Can't find the configuration

sitespeed.io is highly configurable. The grunt-sitespeedio plugin will pass every option to sitespeed, you can see each and every configuration here. Each option needs to be called with full name (meaning the same as using -- for the cli. Say for example that don't need the screenshot for each. Using the cli, you add the flag --browsertime.screenshot false

Doing the same with the grunt plugin:

sitespeedio: {
  default: {
    options: {
      urls: ['http://www.sitespeed.io'],
      browsertime: {
        screenshot: false
      }
    }
  }
}

grunt-sitespeedio's People

Contributors

soulgalore avatar

Watchers

James Cloos avatar Artur Barseghyan avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.