How to detect slow internet connections?

前端 未结 4 1505
终归单人心
终归单人心 2020-12-04 06:52

Currently, most of the popular websites, like google, yahoo detect if the user connection speed is slow and then give a option to load basic version of the website instead o

4条回答
  •  悲哀的现实
    2020-12-04 07:11

    Here's a full implementation I just completed for a site I'm working on. Felt like sharing it. It uses a cookie to dismiss the message (for people who don't mind that the site takes a long time to load.) The message will show if the page is taking longer than 1 second to load. Best to change this to around 5 seconds or so.

    The code below should be added right after the opening tag, because it has to be loaded as soon as possible, but it can't appear before the html or head tag, because these tags need to be present in the DOM when the script is run. It's all inline code, so the scripts and styles are loaded before any other external files (css, js or images).

    
    
    

    The result should look like this:

    enter image description here

    Hope it helps.

提交回复
热议问题