• Hi,

    I registered custom route and return only the title, the permalink and the featured image. I used jQuery $getJSON(); to pull in random recipes for a food blog. But it seems to load very laggy and slowly.

    I don’t know what is the reason. Please advice me!
    Here is the code:

    $(“#getIdeasButton”).on(“click”, function() {
    clearTimeout();
    $(“#cookieLoader”).css(“visibility”,”visible”);
    $(“#cookieLoaderText”).css(“visibility”,”visible”);
    $(“#cookiesDiv”).css(“visibility”, “hidden”);
    $(“#cookieIdeaButton”).css(“display”,”none”);
    setTimeout(function() {
    $(“#cookieLoader”).css(“visibility”,”hidden”);
    $(“#cookieLoaderText”).css(“visibility”,”hidden”);

    $.getJSON(localBlogData.root_url + ‘/wp-json/gbf/v1/randomrecipes’, function(results) {
    $(“#cookiesDiv”).html(`

    <div>${results.map(item => <p class="courseText">Breakfast</p><h1 class="recipeLink"><a href="${item.permalink}">${item.title}</a></h1>)}
    <div class=”phpImage”>${results.map(item => <a href="${item.permalink}"><img id="cookieImage" src="${item.featured_image}" /></a>)}</div></div>
    `);

    $(“#cookiesDiv”).css(“visibility”, “visible”);
    $(“#cookieIdeaButton”).css({“display”:”block”, “margin”:”0 auto”,”margin-top”:”10px”});
    console.log(‘click’);
    });
    }, 500);

    I used the same code for the individual buttons as well.
    Is it the wp jquery combination? Should I use a different method?

    Thanks in advance!

    • This topic was modified 5 years, 2 months ago by tamas088.

    The page I need help with: [log in to see the link]

Viewing 1 replies (of 1 total)
  • Moderator bcworkz

    (@bcworkz)

    You might try asking whoever developed the “gbf” API route for suggestions on improving performance. It’s likely the random nature of the query. Random order DB queries are quite inefficient. It’s not that apparent with smaller DBs. As the size grows it becomes quite obvious.

Viewing 1 replies (of 1 total)

The topic ‘WP rest api loads very slow’ is closed to new replies.