Home Web Front-end JS Tutorial Lazy loading implementation code of js function_javascript skills

Lazy loading implementation code of js function_javascript skills

May 16, 2016 pm 05:49 PM
Lazy loading

Copy code The code is as follows:

//For non-delayed loading functions, conditional judgment will be performed every time it is called.
removefunctionHandler(target, eventType, handler) {
if(target.removeEventListener) {
target.removeEventListener(eventType,handler,false);
}else {
target.detachEvent( "on" eventType,handler);
}
}
//The delayed loading function will overwrite the original old function after the first call. The new function will be called again in the future and will not be called again. Make conditional judgments to improve efficiency
function addHandler(target, eventType, handler) {
if(target.addEventListener) {
addHandler = function(target, eventType, handler){
target.addEventListener (eventType,handler,false);
}
}else{
addHandler = function(target,eventType,handler){
target.attachEvent("on" eventType,handler);
}
}
addHandler(target, eventType, handler);
}


//Conditional preloading
//Conditional preloading ensures that all function calls take the same time. The cost is instrumentation when the script loads. Preloading is suitable for situations where a function will be used immediately and is used frequently throughout the page life cycle.

var addEventHandler = document.body.addEventListener ? function(target,eventType,handler) {
target.addEventListener(eventType,handler,false);
} : function(target,eventType,handler) ) {
target.attachEvent("on" eventType,handler);
}
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

What is the architecture and working principle of Spring Data JPA? What is the architecture and working principle of Spring Data JPA? Apr 17, 2024 pm 02:48 PM

What is the architecture and working principle of Spring Data JPA?

Java JPA performance optimization tips: make your application fly Java JPA performance optimization tips: make your application fly Feb 19, 2024 pm 09:03 PM

Java JPA performance optimization tips: make your application fly

How does Hibernate optimize database query performance? How does Hibernate optimize database query performance? Apr 17, 2024 pm 03:00 PM

How does Hibernate optimize database query performance?

What is the original meaning of dynamic linking and static linking in Linux? What is the original meaning of dynamic linking and static linking in Linux? Feb 05, 2024 pm 05:45 PM

What is the original meaning of dynamic linking and static linking in Linux?

Decoding Laravel performance bottlenecks: Optimization techniques fully revealed! Decoding Laravel performance bottlenecks: Optimization techniques fully revealed! Mar 06, 2024 pm 02:33 PM

Decoding Laravel performance bottlenecks: Optimization techniques fully revealed!

How to prevent iframe loading event How to prevent iframe loading event Feb 19, 2024 am 08:02 AM

How to prevent iframe loading event

What to do if the html image is too large What to do if the html image is too large Apr 05, 2024 pm 12:24 PM

What to do if the html image is too large

What are the disadvantages of Hibernate ORM framework? What are the disadvantages of Hibernate ORM framework? Apr 18, 2024 am 08:30 AM

What are the disadvantages of Hibernate ORM framework?

See all articles