Skip to content

Cache selector results to improve performance #2

@kerrishotts

Description

@kerrishotts

For example (https://github.com/CeroyUno/JavaScriptView/blob/master/js/jsview.js#L46)

if(!$v.select('#' + obj)){
    ...
    $v.select('#' + obj).classList.add('JSVcontainerRight');
    $v.select('#' + obj).classList.add('JSVcontainerTransition');
    ...
}

This is inefficient, as the DOM is being queried each time. Better to do:

var objElement = $v.select('#' + obj);
if (objElement) {
    ...
    objElement.classList.add('JSVcontainerRight');
    objElement.classList.add('JSVcontainerTransition');
    ...
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions