-1

If you have a website running on any server. And the website comes in three different version: Heavy, Medium and Lite. Now you have to load lite version if clients speed is below certain limit (Lets say 500kbps), Medium version (Lets say >500kbps and <25mbps), Heavy version (Lets say more than 25mbps). Can you do it?

I was thinking making a server side script that first check the connection speed with client (don't know how), then based on the speed result redirecting them to respected website. If there is another way, please do tell...

thisisjaymehta
  • 614
  • 1
  • 12
  • 26
  • I guess try this.. load _any_ image in first, test the speed then load the appropriate website front-end (basic or extensive) from there: [Detect internet speed Javascript](https://stackoverflow.com/questions/5529718/how-to-detect-internet-speed-in-javascript). Note: this could have a poor load performance for those on awful internet. – EGC Nov 21 '19 at 01:06
  • 2
    Alternatively - this might be a more recent feature? [Javascript downlink](https://stackoverflow.com/a/47511842/11700321) – EGC Nov 21 '19 at 01:07
  • Yes, you could send data back and forth to and from the Server and test the time. – StackSlave Nov 21 '19 at 01:19

2 Answers2

3

There is no definitive, reliable way to do this and I recommend that you focus on building an optimized site for your intended target audience and their devices.

Internet connections are pretty good around the world. The effort and ongoing maintenance in updating and managing three frontends is not feasible. Instead, focus on serving optimized content and use modern techniques to serve media targetting screen size and device. Limit unnecessary media, compile and bundle scripts, ensure servers are serving gzipped content and place your servers/cdn's near your audience.

If you did, however, want to pursue this exercise you can play with the following idea: You would need to make an initial request to the server to get a timestamp - we want to work with the server's time, not the client which could be off. The client receives the timestamp and responds immediately, passing the timestamp back to the server. The server considers the difference between the two and redirects accordingly.

The problem is that connections are not consistent, and you cannot rely on that first connection to represent the client's connection quality. There may be a dip in connection quality as they are connecting etc.

Samuel Goldenbaum
  • 18,391
  • 17
  • 66
  • 104
  • If I do large transfer than timestamp (like about 500kb to 1mb) wouldn't that help in increasing accuracy of measured speed? – thisisjaymehta Nov 21 '19 at 09:33
  • Why would you want to do this? – Samuel Goldenbaum Nov 22 '19 at 00:45
  • No particular reason. Just exploring the possibilities for my making my website. I made one in wix but its very heavy with all the fonts and background images... So if I can do this. I would make a lite version for my site as well... Its a personal site so no problem of maintenance.. – thisisjaymehta Nov 22 '19 at 01:34
  • 1
    End of the day, you can do whatever you like ;-) However, you are now talking about transferring files sizes that would equal the total of an optimized site just to determine latency. I would focus on image optimization including lazy loading images as needed. – Samuel Goldenbaum Nov 22 '19 at 05:16
-2

To maintain two or more server side codes is not easy or ideal. Focus on optimization especially on the website assets such as images. Images form about 75% of site load times.

Ideally you can have multiple image source to start with img srcset.

What you are talking about is obtainable with respect to images and videos . You can have more than three images and the browser will select the best based on the available connection speed.