Giter Site home page Giter Site logo

preload-polyfill's Introduction

Preload Polyfill

it just works...

What & Why

preload seems the best async loading mechanism today...

https://caniuse.com/#search=preload

some good reads:

Install with npm

npm install @digitalkaoz/preload-polyfill

Usage

This Polyfill supports the following types:

  • js
  • css
  • font
  • image
  • audio (not well tested)
  • document (not well tested)
  • embed (not well tested)
  • fetch (not well tested)
  • object (not well tested)
  • track (not well tested)
  • worker (not well tested)
  • video (not well tested)

https://developer.mozilla.org/en-US/docs/Web/HTML/Preloading_content

Integration in your Page

the polyfill and the invoke script are seperated

    <script src="/dist/preload-polyfill.min.js"></script>
    <script src="/dist/preload-polyfill-invoke.min.js"></script>

additionally you need an inline script (for browsers that are preload capable, preloading stuff could be faster than loading an external sync script, and you would miss the load event)

    <script>/dist/preload-polyfill-inline.min.js</script>

Preloading Stuff

simply use it as follows:

<link rel="preload" as="script" href="jquery.js" />

Additional Features

beware those are not spec compliant features

critical

those resources will be fetched non blocking, but executed first in order they appear

<link rel="preload" critical as="script" href="jquery.js" />

fonts

to preload fonts correctly you have to set a name property on the links

<link rel="preload" name="FontName" weight="bold" as="font" crossorigin type="font/woff2" href="font.woff2" />

module

those resources will only be fetched if browser understands es6

<link rel="preload" module as="script" href="app.es6.js" />

nomodule

those resources will only be fetched if browser cant understand es6

<link rel="nomodule" as="script" href="app.legacy.js" />

AllScriptsExecuted Event

window.onload can be fired even if not all preloaded scripts are executed, therefore we dispatch an event AllScriptsExecuted which indicates all preloaded stuff is executed too.

Development

$ npm start

now visit https://localhost:5000

TODOS

Thanks

preload-polyfill's People

Contributors

christianhaller3000 avatar digitalkaoz avatar moehlone avatar patrickeickmeier avatar patrickeickmeier0770 avatar philippmoehler0440 avatar

Stargazers

 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

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.