How to make the 1st part of the site loads first? (Like in Google PageSpeed)

前端 未结 14 1503
野性不改
野性不改 2021-01-31 11:01

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 w

14条回答
  •  有刺的猬
    2021-01-31 11:30

    this is going to be ugly! You should definitely consider using ajax calls to load page fragments AFTER a first content stage is loaded! This is going to break almost all known web standards, but it might render the website in parts....

    this being said: here's the ugly stuff

    First: get rid of the tag of your website, start with the DO NOT use a tag either. Now send your html-code in the order you want it to be loaded (top first) using echo ... after each closing tag of a group (say or

    ) use flush(); ob_flush(); this will send all known content to the browser immediately. The browser now decides if it can render the known content or not and if it will (based on the browser specifics and user settings) but with few exceptions it will. some browsers like to wait for the closing body-tag that's why we dropped it, others even wait for the closing html tag (safari afair) that's why we dropped that too. If you use the echo-flush scenario wisely you should be able to split the page into renderable parts which most browsers will display without an error.

    Again... don't do it this way.. it's bad, ugly and not even near any web standards

    But you asked for it.

提交回复
热议问题