Giter VIP home page Giter VIP logo

preloadables's Introduction

Preloadables

Preloadables is a Rails gem exposing a set of view helpers for outputting HTML metadata related to domains, assets and pages that you would like to preload/prerender. Adding these links to your can dramatically speed up your website by directing the browser to perform certain actions before they're needed.

Code Climate

Test Coverage

A word of caution: while preloading assets and prerendering pages is a brilliant technology that can dramatically speed up your website it can consume a ton of local resources and make too many network requests on connections that are bandwidth limited. I strongly encourage you to only preload assets that you're very confident the visitor will need soon and definitely only prerender a page if you're certain the visitor will go there next.

Installation

Add gem 'preloadables' to your Gemfile or if you're using gemspec:

Gem::Specification.new do |s|
  s.add_dependency 'preloadables'
end

Usage

<!-- in your views/layouts/layout.html.erb or maybe an _head.html.erb partial -->
<doctype html>
<html>
  <head>
    <title>my webpage</title>

    <%= preloadables_meta(@preloadables) %>

    <!-- stylesheet links, js, etc... -->
  </head>

  <body>
    <!-- site content... -->
  </body>
</html>
# in your controllers/my_app/application_controller.rb controller or other route controller
module MyApp

  def show
    @preloadables = {
      domains: [
        'my.asset.subdomain.com'
      ],
      assets: [
        '/assets/js/application_helper.js',
        '/assets/stylesheets/contact_page.css'
      ],
      pages: [
        '/page_2.html'
      ]
    }

    render :show, layout: 'my_app/layout'
  end

end

Methods

preloadable_meta is the main method and takes a hash of arguments for outputting all 3 kinds of preloading meta tags. If you prefer, you can also use one of the 3 other methods for more specific control.

preloadable_meta

Takes a hash with properties domains, assets and pages(all of which are arrays) and outputs relevant meta tags for each of them.

preload_domains_meta

Takes an array of domains to prefetch dns for.

preload_assets_meta

Takes an array of asset urls to prefetch.

prerender_pages_meta

Takes an array of page urls to prerender.

Development

  • Clone the repo
  • Run gem install bundler
  • Run bundle
  • Make sure everything works by running bundle exec rake
  • Make your changes in the tests and documentation and then the code
  • Commit changes, push them up to a branch and make a pull request

Testing

The default rake task includes running the tests so a simple rake on the command line with run the test suite.

License

This project is released under a Creative Commons Attribution-ShareAlike license. This requires that you both credit the original author and open source your own project. Long live open source software!

preloadables's People

Contributors

jacopotarantino avatar vcarballo avatar

Watchers

Vladimir Carballo 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.