Przeglądałem ostatnio mój skrypt na troszke gorszym komputerze i rzuciło mi sie w oczy, że nei dziąła on zbyt wydajnie.
Zasatanawiam sienad optymalizacją skryptów js, zauważyłem, że wiele skryptów dziąła nonstop, niezaleznie czy jest potrzebna czy nie w danym momencie.
Np mam w pliku ze skryptami taki kod:
Kod
$(document).ready(function() {
//hiding tab content except first one
$(".tabContent").not(":first").hide();
// adding Active class to first selected tab and show
$("ul.tabs li:first").addClass("active").show();
// Click event on tab
$("ul.tabs li").click(function() {
// Removing class of Active tab
$("ul.tabs li.active").removeClass("active");
// Adding Active class to Clicked tab
$(this).addClass("active");
// hiding all the tab contents
$(".tabContent").hide();
// showing the clicked tab's content using fading effect
$($('a',this).attr("href")).fadeIn('slow');
return false;
});
});
//hiding tab content except first one
$(".tabContent").not(":first").hide();
// adding Active class to first selected tab and show
$("ul.tabs li:first").addClass("active").show();
// Click event on tab
$("ul.tabs li").click(function() {
// Removing class of Active tab
$("ul.tabs li.active").removeClass("active");
// Adding Active class to Clicked tab
$(this).addClass("active");
// hiding all the tab contents
$(".tabContent").hide();
// showing the clicked tab's content using fading effect
$($('a',this).attr("href")).fadeIn('slow');
return false;
});
});
skrypt zakąłdek. Wykorzystuje to tylko w jednym wyskakującym okienku, cała reszta strony nie potrzebuje tego.
Patrzac na skrypt widać, że ukrywa on elementy, wyświetla inne, cały czas przekopuje strone, widze, że jest sporo takich skrypcików.
Jak sobie z tym radzicie?
mam zrobić 30 plików se skryptami js i doładowywac w odpowiednim czasie?