kubetail-org / loadjs

A tiny async loader / dependency manager for modern browsers (899 bytes)
MIT License
2.57k stars 149 forks source link

Announcement: New version with support for image loading (v3.5.4) #63

Open amorey opened 6 years ago

amorey commented 6 years ago

Hi Everyone,

I just wanted to let you know that the latest version of LoadJS (v3.5.4) includes support for images (.png|.jpg|.gif|.svg). Here are some things you can do with the new functionality:

  1. Execute code after an image has finished downloading

    loadjs(['/path/to/foo.png', '/path/to/bar.css', '/path/to/thunk.js'], function() {
      /* foo.png, bar.css and thunk.js loaded */
      var img = document.createElement('img');
      img.src = '/path/to/foo.png';
      document.body.appendChild(img);
    });
  2. Detect download errors

    loadjs(['/path/to/foo.png', '/path/to/bar.css', '/path/to/thunk.js'], {
      success: function() { /* foo.png, bar.css and thunk.js loaded */ },
      error: function(pathsNotFound) { /* at least one path didn't load */ }
    });
  3. Include images in bundle definitions

    loadjs(['/path/to/foo.png', '/path/to/bar.css', '/path/to/thunk.js'], 'foobarthunk');
    
    loadjs.ready('foobarthunk', function() {
      /* foo.png, bar.css and thunk.js loaded */
    });
  4. Force treat a file as an image using an "img!" prefix

    loadjs(['img!/path/to/image.custom'], function() {
      /* image.custom loaded */
    });

I hope this helps to simplify your frontend loading issues! Please let me know if you have any questions or suggestions.

Andres

https://github.com/muicss/loadjs