maciej-gurban / responsive-bootstrap-toolkit

Responsive Bootstrap Toolkit allows for easy breakpoint detection in JavaScript
MIT License
363 stars 89 forks source link

its changing things that allready changed makes the page slow #40

Closed rommilg closed 8 years ago

rommilg commented 8 years ago
(function ($, document, window, viewport) {
    var lastviewport;
    var changebtnssize = function () {
        if (viewport.is('<=sm')) {
            $('.btn-resopnsive').removeClass('btn-lg').addClass('btn-sm');
        };
        if (viewport.is('md')) {
            $('.btn-resopnsive').removeClass('btn-sm').removeClass('btn-lg');
        };
        if (viewport.is('>md')) {
            $('.btn-resopnsive').removeClass('btn-sm').addClass('btn-lg');
        };
    };
    $(document).ready(function () {
        changebtnssize();
        console.log('Current breakpoint:', viewport.current());
    });
    $(window).resize(viewport.changed(function () {
        if (lastviewport == viewport.current()) { return };
        lastviewport = viewport.current();
        changebtnssize();
        console.log('Current breakpoint:', viewport.current());
    }));
}(jQuery, document, window, ResponsiveBootstrapToolkit));
maciej-gurban commented 8 years ago

Could you clarify what exactly do you mean? The library itself should not create any overhead for you since all it does is operate on visibility divs that are injected into DOM once, on initialization. Running any of the functions also does nothing computation heavy, and does not touch DOM at all.

Based on what do you suspect it's the library that's slowing down your page? How did you measure that slow down? How does it manifest?

It looks like your mass change of all .btn-responsive could be the culprit if there's a lot of them, but that's a pure guess.