pushState and popState, poor performance

Asked

Viewed 20 times

0

I am wearing it. load() to have asynchronous requests, but I realized that when I click on the arrows to go and come back nothing happened, I decided to search further and discovered the History API that controls this whole process of arrows, then I developed this code to try to solve the problem of arrows not loading the pages or later

function carregarConteudo(href){
   $('.body').load(href)
}

$(document).ready(function () {
    
    $('a').on('click', function(e){
        e.preventDefault()
        
        let href = $(this).attr('href')

        history.pushState(null, null, href);

        carregarConteudo(href)
    })    

    $(window).bind("popstate", function() {

        link = location.pathname; // get filename only
        carregarConteudo(link);
    });
});

but using this code, when I click to go back one page or go to another, the site hangs and gets very slow, someone knows what can be?

here is a screenshot of the performance of the page during that process

notice the peak and the delay in each click to go back and go, I also noticed an exaggerated use of cpu

inserir a descrição da imagem aqui

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.