Connectivity is not binary. Although modern mobile networks make high-resolution video viable on a phone, older generations remain widespread — in 2020, 3G, 2G and similar networks accounted for nearly half of all connections worldwide. Phasing them out is slow, so many users still face page loads reminiscent of early home internet.

Meanwhile, the average modern site is resource-heavy, full of images and animations. On an underpowered device over a fragile connection, a typical page can take close to a minute to finish loading. Part of the problem is that developers tend to treat hardware and network conditions as binary choices: desktop or smartphone, online or offline. Real circumstances are far more nuanced.

Two properties worth reading

To bridge the gap for users on modest hardware and spotty connections, evaluate their conditions through two browser properties:

  • navigator.deviceMemory
  • navigator.connection

Those values can drive decisions such as lowering the quality of the images you serve. There is a caveat for Jamstack sites and server-rendered apps: navigator, like any browser API, is unavailable at render time. The usual workaround is to ship a pile of responsive image markup, but that approach brings a significant pain point — inefficient scaling. An image CDN such as ImageEngine avoids this and other responsive-image pitfalls by applying automated, smart adjustments to requested resources on the fly.

Varying compression by connection in React

For network adaptation, you can detect the connection type and instruct an image CDN to vary compression according to connection quality. In React, that looks like this:

import React, { useState, useEffect } from 'react'

const useConnectionType = (defaultConnectionType) => {

  const isSupported = navigator?.connection?.effectiveType
    ? true
    : false

  const [connectionType, setNetworkStatus] = useState(
    isSupported
      ? navigator.connection.effectiveType
      : defaultConnectionType
  )

  useEffect(() => {
    if (isSupported) {
      const { connection } = navigator
      const updateConnectionType = () => {
        setNetworkStatus(connection.effectiveType)
      }

      connection.addEventListener('change', updateConnectionType)

      return () => {
        connection.removeEventListener('change', updateConnectionType)
      }
    }
  }, [])

  return [ connectionType, setNetworkStatus ]
}

const imageCDNHost = 'images.foo.com

function ConnectionAwareComponent () {

  const [ connectionType ] = useConnectionType()

  let compressionLevel = 0

  switch (connectionType) {
    case 'slow-2g':
      compressionLevel = 65
      break
    case '2g':
      compressionLevel = 50
      break
    case '3g':
      compressionLevel = 30
      break
    case '4g':
      compressionLevel = 0
      break
  }

  return (
    <div>
      {/* Apply variable compression via dedicated directive */}
      <img src={`${imageCDNHost}/?imgeng?=cmpr_${compressionLevel}`} />
    </div>
  )
}

The idea can be pushed further for users on very sluggish, unreliable networks: render blurred images and offer a way to fetch a higher-resolution version on demand, or build a performance scoring system and adjust what you send based on that score.

Conversely, a fast 4G connection does not mean the user wants to spend data — they may be on roaming. Enabling Client Hints lets site owners detect a data saver flag and respond to the user's preference.

Why it matters beyond emerging markets

Weak CPUs, modest memory and poor connections are not imaginary constraints; they pose real user-experience problems for potentially hundreds of millions of people. Some companies already build inclusive experiences into their products — Netflix and Spotify adjust streaming quality to network conditions, and many others perform automatic image optimizations behind the scenes.

Even if developing regions are not your target market, a visitor browsing from a rural area of a developed country will likely have a jarring experience if served the full-weight version of a site. A couple of small tweaks to what you send and display can make that experience considerably more considerate. Using an image CDN like ImageEngine simplifies the process: it responds automatically to Client Hints for network constraints, improving the experience for network-constrained visitors while keeping the developer workflow simple.