是有可能直接其中页面的元件用浏览器的第一画? [英] Is it possible to direct which elements of a page are painted first by the browser?

查看:91
本文介绍了是有可能直接其中页面的元件用浏览器的第一画?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否有什么办法可以控制浏览器的画,比如我想在第一页的顶部加载元素,因此用户可以看到的内容通俗易懂。在页面底部的元素可以加载最后因为用户不会看到他们,直到他们向下滚动。

I wanted to know if there was any way to control browser painting, for example I'd like to load elements at the top of the page first so users can see content straightaway. The elements at the bottom of the page can load last as the user will not see them until they scroll down.

我期待优化我的网站目前有6秒的加载时间,我想它弄下来到1秒。这主要是受到JS和图像造成的。我知道,同时降低这些将意味着我不会需要担心指导绘画,但出于兴趣我只是想知道是否有可能?

I'm looking to optimize my site which currently has a 6 second load time and I'd like to get it down to 1 second. This is mostly being caused by JS and images. I know that reducing both these will mean I wont need to worry about directing the painting but out of interest I just wanted to know if it was possible?

道歉,如果我的浏览器绘画的理解是非常基本的。

Apologies if my understanding of browser painting is very basic

推荐答案

它并不难。你需要的是阿贾克斯。加载inital标记,然后通过AJAX加载页面的其余部分。

its not that difficult. all you need is ajax. load the inital markup and then load the rest of the page via ajax.

刚装入小标记您initally要显示给用户的页面。那么作为用户向下滚动可以使Ajax调用并获得XML或JSON或也HTML文件,使它们你页面上,例如:

just load the page with little markup which you initally want to show to the user. then as user scrolls down you can make ajax calls and get xml or json or also html files and render them on you page, for example:

$(window).on( "scroll" , function() {

 var $document = $(document);
 var $window = $(this);

 if( $document.scrollTop() >= $document.height() - $window.height() - 400 ) {
    //make ajax call here and load the data
 }

 });

另请阅读

这篇关于是有可能直接其中页面的元件用浏览器的第一画?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆