Giter Site home page Giter Site logo

hoist.js's Introduction

Hoist.js

Even over a fast connection, the user experience on image-heavy websites can suffer from slow loading times. Hoist.js is a library that wraps up the logic of loading a large collection of images a few at a time. It's similar in spirit to the 'infinite scroll' approach but instead opts to preemptively load the entire collection, rather than waiting for the user to scroll to load more. Such an approach is not suitable for massive collections of images but, for a large collection, the result is quite effective.

Example implementation

var urls = [
  'http://example.com/images/0.jpeg',
  'http://example.com/images/1.jpeg',
  'http://example.com/images/2.jpeg',
  'http://example.com/images/3.jpeg',
  'http://example.com/images/4.jpeg',
  'http://example.com/images/5.jpeg',
  'http://example.com/images/6.jpeg',
  'http://example.com/images/7.jpeg',
  'http://example.com/images/8.jpeg',
  'http://example.com/images/9.jpeg',
  'http://example.com/images/10.jpeg'
];

var hoister = new Hoist({
  urls: urls,
  container: document.getElementById('container'),
});

hoister.launch();

The above will load the images for the first four urls into the browser's memory, create DOM nodes for each of them and append them to the container div. It will then move on to the next four and perform the same steps until it runs out.

Hoist.js can be configured to do the following:

  • query an API endpoint for retrieving the list of URLs via an AJAX request
  • use a custom render / DOM append function
  • rather than an array of simple URLs, accept an array of objects whose properties can be used for more complex rendering

Hoist.js has no external dependencies.

hoist.js's People

Contributors

johnfriel avatar

Watchers

 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.