简体   繁体   English

WordPress Ajax 调用非常缓慢和紧张

[英]WordPress Ajax call very slow and jittery

I've been working on a website for some time now and while they do have a large amount of content and I have upgraded them, the AJAX load more call on the masonry grid is very slow.我已经在一个网站上工作了一段时间,虽然他们确实有大量内容并且我已经升级了它们,但 AJAX 加载更多砖石网格上的调用非常慢。 I have tried caching and using a CDN but it's still taking a very long time, particularly after the first instance.我尝试过缓存和使用 CDN,但仍然需要很长时间,尤其是在第一个实例之后。

Does anyone have any ideas?有没有人有任何想法? Website is www.noctismag.com网站是www.noctismag.com

Here's the script I'm using to run it, in my footer.这是我用来运行它的脚本,在我的页脚中。

<script>
    jQuery(function ($) {
        /* Masonry + Infinite Scroll */
        var $container = $('#grid-container');
        $container.imagesLoaded(function () {
            $container.masonry({
                itemSelector: '.post'
            });
        });
        $('#grid-container').masonry({
            itemSelector: '.post'
            , columnWidth: 258
        });
        $container.infinitescroll({
            navSelector: '#page-nav'
            , nextSelector: '#page-nav a'
            , itemSelector: '.post'

        }, function (newElements) {
            var $newElems = $(newElements).css({
                opacity: 0
            });
            $newElems.imagesLoaded(function () {
                $newElems.animate({
                    opacity: 1
                });
                $container.masonry('appended', $newElems, true);
            });
        });
        $(window).unbind('.infscr');
        jQuery("#page-nav a").click(function () {
            jQuery('#grid-container').infinitescroll('retrieve');
            return false;
        });
        $(document).ajaxError(function (e, xhr, opt) {
            if (xhr.status == 404) $('#page-nav a').remove();
        });
    });
</script>

Does the Ajax request send back HTML code? Ajax 请求是否发回 HTML 代码? If it's the case try to change the code, Ajax call must return data as a JSON string and a front-end function will transform that data to render it on grid.如果是这种情况尝试更改代码,Ajax 调用必须将数据作为 JSON 字符串返回,并且前端函数将转换该数据以将其呈现在网格上。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM