Detect internet connection before webrequest

Where is the best place to check for internet before registering a web requesting background service? At first I registered the background service in the initialize() function of the app as the tutorials suggest, but that seems to initialize before I have an internet connection and misfires the web request making it wait another 30 min before it fires again (or not firing it at all if I check for internet there since that is only called once when the app starts). So I moved it to the compute() function of the view like below. This works but I wonder if there is a better way to do it. Thanks.

    function compute(info) {
   
        var isConnected= System.getDeviceSettings().connectionAvailable;
        var now = Time.now();
        var lastTime = Background.getLastTemporalEventTime();
     
        if ((isConnected and now.greaterThan(lastTime.add(THIRTY_MINUTES))) or (isConnected and lastTime == null)) {
            Background.registerForTemporalEvent(Time.now());
        }
     }