Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use yepnope

Shulou Source: shulou.com Published: 2022-06-03 11:02:36 11月15日 Update

Editor to share with you how to use yepnope, I hope you will get something after reading this article. Let's discuss it together.

Yepnope.js is an ultra-fast conditional asynchronous resource loader that allows you to load only the resources you use (css and js).

A typical example of yepnope.js:

Yepnope ({

Test:Modernizr.geolocation

Yep:'normal.js'

Nope: ['polyfill.js','wrapper.js']

})

This example indicates that normal.js is loaded if Modernizr.geolocation is true, polyfill.js and wrapper.js are loaded if false.

Yepnope complete syntax:

Yepnope ([{]

Test:/*boolean (ish) input condition * /

Yep:/*array (ofstrings) | Resources loaded when the string- condition is true * /

Nope:/*array (ofstrings) | Resources loaded when the string- condition is false * /

Both:/*array (ofstrings) | string- condition is loaded regardless of whether it is true or false * /

Load:/*array (ofstrings) | string- condition is loaded regardless of whether it is true or false * /

Callback:/*function (testResult,key) | object {key:fn} callback function * /

Function executed after complete:/*function loading is completed * /

},.])

Why use yepnope:

Only 1.6K after Gzip is smaller than most resource loaders.

Can load CSS and JS

Yepnope has passed the tests of all the browsers the author can find.

Yepnope completely separates resource loading and execution, so that you can control the order in which resources are executed

Provide a logical combination of friendly API and facilitation resources

Modular design, you can expand your own functions (see Prefixes and filters later)

Encourage loading resources on demand

Integrated into Modernizr

By default, it is always executed in the order of the resource list (the list of files you provide).

Can handle resource fallback (fallback), and still give priority to parallel download dependent scripts, take a look at the code is easier to understand.

After reading this article, I believe you have a certain understanding of "how to use yepnope". If you want to know more about it, you are welcome to follow the industry information channel. Thank you for reading!

Tags: Resources conditions order functions instances true or false articles code authors typical functions only finished files time more modules browsers knowledge later Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Linux Microsoft Apple Shulou Information Docker