Skip to content

Utils to speed up page load by using critical css & deferred scripts initialization

License

Notifications You must be signed in to change notification settings

izikaj/izi_lightup

Repository files navigation

Izi Lightup

Utils to speed up page load by using critical css & deferred scripts initialization

Usage

JS utils

activeOn

activeOn(function() {
  console.log("should activate large client oriented JS here");
});

waitFor

waitFor("jQuery", function() {
  $("body").css("background", "orange");
});
waitFor("jQuery", function() { return $.fn && $.fn.select2 }, function() {
  $("select").select2();
});

miniRequire

miniRequire("main-bundle", "/assets/application.js");
var src = "https://cdnjs.cloudflare.com/ajax/libs/tooltipster/4.2.8/js/tooltipster.bundle.min.js"
miniRequire("main-bundle", src, function() {
  $('.tooltip').tooltipster();
});

miniPreload

miniPreload("/assets/font.woff2");
miniPreload("/assets/extra.css", function(ctx) {
  ctx.node.rel = "stylesheet";
});

Requirements

  • ruby 2.3+
  • rails 3.x+ with sprockets 2.x+

Development

Changelog

  • Add support for rails 3.2 (ruby 2.3.8 + rails 3.2 + sprockets 2.2)
  • Add multiple dependencies/rubies versions tests
  • Add tests

TODO

  • Add more JS-plugins
  • Add tests to cover JS-code
  • Refactor JS-code
  • Add some docs/examples
  • Add fast-image gem for images size detection
  • Add more tests

install deps

bundle exec rake matrix:install

run tests

Rspec

bundle exec rake matrix:spec

Karma

npm test
or
npm test:karma

All in one (karma + current rspec)

npm test:all

Run karma in browser

bundle exec rails server

and visit root page of server

Currently testing on versions:

  • ruby 2.3.8 + rails 3.2 + sprockets
  • ruby 2.3.8 + rails 4.2 + sprockets 3.x
  • ruby 2.3.8 + rails 5.0 + sprockets 3.x
  • ruby 2.3.8 + rails 5.2 + sprockets 3.x
  • ruby 2.5.8 + rails 4.2 + sprockets 3.x/4.x
  • ruby 2.5.8 + rails 5.0 + sprockets 3.x/4.x
  • ruby 2.5.8 + rails 6.0 + sprockets 3.x/4.x

About

Utils to speed up page load by using critical css & deferred scripts initialization

Resources

License

Stars

Watchers

Forks

Packages

No packages published