Code Monkey home page Code Monkey logo

aload's Introduction

aload.js

NPM version License Build status Coverage Status Dependency status devDependency status downloads

Loads images, background images, scripts, styles, iframes, videos and audios asynchronously (just 241 bytes).

API

aload([nodeList])

Loads images, background images, scripts, styles, iframes, videos and audios asynchronously.

  • nodeList {NodeList} [optional] - A NodeList of elements. By default, it is the result of querySelectorAll('[data-aload]').
aload();

Installation

$ npm install aload

$ bower install aload

Note: I recommend to use aload inline in your HTML.

As standalone just include aload function (just 241 bytes) inline into your HTML file:

<script>
  function aload(t){"use strict";var e="data-aload";return t=t||window.document.querySelectorAll("["+e+"]"),void 0===t.length&&(t=[t]),[].forEach.call(t,function(t){t["LINK"!==t.tagName?"src":"href"]=t.getAttribute(e),t.removeAttribute(e)}),t}
</script>

Usage

  1. You should use data-aload attributes instead of src or href in your HTML tags (an image for example):
<img data-aload="http://foobar.com/foo.png" width="400" height="300">
  • data-aload - URL of the source.
  1. Now, you can start to load your images asynchronously!
// Onload
window.onload = function () {
  aload();
};

You can load everything asynchronously.

  • images
  • background images
  • scripts
  • styles
  • iframes
  • videos
  • audios

IMG

<img data-aload="http://foobar.com/foo.png" width="400" height="300">

Backgrounds

  1. You must add the following CSS snippet.
[data-aload] { background-image: none !important; }
  1. Your own CSS.
.foo {
  background: url('http://foobar.com/foobar.png');
}
  1. In your HTML.
<div data-aload class="foo"></div>

SCRIPT

<script data-aload="http://foobar.com/foo.js"></script>

LINK (styles)

<link data-aload="http://foobar.com/foo.css" rel="stylesheet">

IFRAME

<iframe data-aload="http://foobar.com" src="javascript:false"></iframe>

VIDEO

<video data-aload="http://foobar.com/bar.mp4" controls></video>

AUDIO

<audio data-aload="http://foobar.com/foo.mp3" controls></audio>

Progressive Enhancement

If you are a front-end developer you must know about Progressive enhancement. Progressive enhancement focuses on the content and it must be showed without JavaScript.

For example, to show images when JavaScript is not enabled you should include the images inside <noscript> tag.

<img data-aload="http://foobar.com/foo.png"
     src="data:image/gif;base64,R0lGODlhAQABAIAAAMLCwgAAACH5BAAAAAAALAAAAAABAAEAAAICRAEAOw=="
     width="400"
     height="300">
<noscript>
    <img src="http://foobar.com/foo.png" width="400" height="300">
</noscript>

Development

  1. Install Git and NodeJS.

  2. Install gulp:

     $ npm install gulp -g
    
  3. Open your terminal and clone aload by running:

     $ git clone [email protected]:pazguille/aload.git
    
  4. Go to aload's folder:

     $ cd aload
    
  5. Move to develop branch:

     $ git checkout develop
    
  6. Install its dependencies:

     $ npm install
    
  7. Code, code code!

  8. Send pull requests.

NPM tasks

  • npm run dist: Creates a distribution version of aload. You should find two files: ./dist/aload.js and ./dist/aload.min.js.
  • npm test: Runs mocha tests.

With ❤️ by

License

MIT license. Copyright © 2016.

aload's People

Contributors

craigmdennis avatar greenkeeper[bot] avatar montogeek avatar pazguille avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

aload's Issues

Version 10 of node.js has been released

Version 10 of Node.js (code name Dubnium) has been released! 🎊

To see what happens to your code in Node.js 10, Greenkeeper has created a branch with the following changes:

  • Added the new Node.js version to your .travis.yml

If you’re interested in upgrading this repo to Node.js 10, you can open a PR with these changes. Please note that this issue is just intended as a friendly reminder and the PR as a possible starting point for getting your code running on Node.js 10.

More information on this issue

Greenkeeper has checked the engines key in any package.json file, the .nvmrc file, and the .travis.yml file, if present.

  • engines was only updated if it defined a single version, not a range.
  • .nvmrc was updated to Node.js 10
  • .travis.yml was only changed if there was a root-level node_js that didn’t already include Node.js 10, such as node or lts/*. In this case, the new version was appended to the list. We didn’t touch job or matrix configurations because these tend to be quite specific and complex, and it’s difficult to infer what the intentions were.

For many simpler .travis.yml configurations, this PR should suffice as-is, but depending on what you’re doing it may require additional work or may not be applicable at all. We’re also aware that you may have good reasons to not update to Node.js 10, which is why this was sent as an issue and not a pull request. Feel free to delete it without comment, I’m a humble robot and won’t feel rejected 🤖


FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

Automatic asynchronous loading without defining `data-aload`

I might just be missing something: Is it possible to load all images (or other elements) asynchronously, even if the data-aload attribute isn’t defined? For example, if there’s a bunch of user-generated content, placing data-aload on all the content seems a bit odd and would only work for newly generated content.

Component Build broken

Hi,

The latest update broken the option to install your library using Component.
Is this something planned to come back?

Cheers

$(window) doesn't work

Hi! thank you for great plugin :)
but I have one problem,$(window) as selector not work.
For ex. $(window).load, $(window).scroll(), etc.

Publish to npm

I love that this tiny plugin, doesn't rely on jquery. Will be great to publish it on npm and make it available for custom builds using browserify/webpack etc

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.