如何使网站的第一部分首先加载? (就像Google PageSpeed一样) [英] How to make the 1st part of the site loads first? (Like in Google PageSpeed)

查看:94
本文介绍了如何使网站的第一部分首先加载? (就像Google PageSpeed一样)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个非常大的网站,加载需要很长时间。大约需要120秒。我想要做的是加载上半场网站负载第一。然后,用户可以在其他部分被加载时进行浏览。



我正在尝试做的是以下。




    根据我的知识是的,因为Google PageSpeed能够做到这一点吗?
  • 。但问题是,如果我使用PageSpeed,我将不得不更改我的DNS服务器设置等。我希望自己做这件事。




    • 我该如何处理它?<​​/ strong>

    • 我应该使用何种类型的技术?
    • ul>

      鉴于页面具有 .php 扩展名并以PHP语言编写。



      您只能加载在加载过程中必需的内容然后使用jquery和ajax,你可以加载剩余的内容。

      这样用户就可以很容易地浏览和加载已经加载的部分,而另一部分将会异步加载。



      jQuery ajax 帖子方法可以帮助您解决这个问题。



      例如可能是,

      如果页面中有5部分内容,需要立即加载2部分


      1. 该页面将加载2个部分,因此加载时间比5个部分少得多。


      2. 加载文档后,您将使用ajax加载剩余的3个部分。
        Ajax会将请求发送到您的网站的特定页面(可以命名为AjaxRequestHandler.php),并且该页面将处理您的请求并为此生成html,并将其发送回您的主页面将只显示这个返回的html,并且这一切都是异步发生的,所以用户将能够与最初加载的2部分进行通信


      即使您对网络技术还不熟悉,我想您必须具备至少ajax和异步调用等方面的知识才能实现延迟加载。



      编辑:



      您的这个问题


      除了AJAX有没有办法解决这个问题?


      我认为如果他们可以帮忙的话,可以尝试iframe。



      在页面加载时加载没有iframe的主要内容,而在加载页面后加载iframe中的其他内容。



      这jsF iddle



      jsfiddle.net/cGDuV/



      可以帮助您了解iframe的延迟加载, 发布的计算器。



      如果您想避免使用jquery,可以使用javascript。


      I have a very large site and it takes pretty long time to load. It takes around 120 seconds. What I'm trying to do is loads 1st half of the site loads 1st. Then user can surf while others parts are being loaded.

      What I'm trying to do is below.

      • 1st of all is this possible ?

      According to my knowledge Yes since Google PageSpeed does that. But the problem is if I use PageSpeed I would have to change my DNS server settings and etc. I would like to do this myself.

      • How can I get it done ?
      • What type of technology should I use ?

      Given that pages have the .php extension and written in PHP language.

      解决方案

      You can use the concept of lazy loading.

      You can load only content that is necessary during the load then using jquery and ajax you can load the remaining content.

      In this way user can surf and interact easily with the the part already loaded while the other part will be loading asynchronously.

      jQuery ajax or post method can help you on this.

      A simple example could be,

      If There are 5 parts of contents in your page, 2 needs to be loaded immediately

      1. The page will be loaded with 2 parts loaded, so it will take quite less time than 5 parts loading

      2. After document is loaded you will use ajax to load the remaining 3 parts. Ajax will send request to the specific page of your website(can be possibly named AjaxRequestHandler.php) with some parameters, and this page will process your request and generate html for this and will send it back to your main page which will just show this returned html and this all be happening asynchronously, so the user will be able to communicate with the initially loaded 2 parts

      And even if you are new to web technologies, I suppose you have to have the knowledge of atleast ajax and asynchronous calls etc. to achieve lazy loading.

      Edit :

      For your this question

      Except AJAX Is there way around for this?

      I think you can try iframes if they can help.

      Loading the main content in the page load without iframe while loading other contents in the iframes after pages is loaded.

      This jsFiddle

      jsfiddle.net/cGDuV/

      can help you understand lazy loading with iframe, mentioned in this post of stackoverflow.

      You can use javascript for the same if you want to avoid jquery.

      这篇关于如何使网站的第一部分首先加载? (就像Google PageSpeed一样)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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