title: How to detect older versions of iOS and prevent a script from loading
body: <p>Our company recently decided to stop support for iOS 12.3 and below. However a small fraction of users are still on older devices that do not support newer JavaScript operators or syntax.</p>
  <p>In order to prevent our script from affecting these users we are looking for ways to stop our script from loading if iOS v12.3 or below is detected.</p>
  <p>Our JS code is loaded onto client websites via script tags like so:</p>
  <pre><code>&lt;script src=&quot;exampledomain.com/example.js&quot;&gt;&lt;/script&gt;
  </code></pre>
  <p>Our first idea was to detect the useragent like <a href="https://stackoverflow.com/questions/9038625/detect-if-device-is-ios">this post</a> but there are some problems with this approach.</p>
  <ul>
  <li><p>It is strongly advised against for several reasons outlined <a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Browser_detection_using_the_user_agent" rel="nofollow noreferrer">here</a></p>
  </li>
  <li><p>Detecting the user agent within our script means that it still loads and throws errors when iOS &lt;12.3 encounters syntax it cannot handle.</p>
  </li>
  <li><p>Detecting the user agent using conditional javascript on our client websites before loading our script is a possibility but difficult to maintain and not ideal for our customers.</p>
  </li>
  </ul>
  <p>Another option is to point the src of our script element to a script that can detect the UA and serve different versions of our script.  However our script is time sensitive and the additional time it takes to make 2 requests instead of 1 is something we would like to avoid.</p>
  <p>Lastly it is also possible to detect iOS versions without using the useragent by specifically targetting features that are not supported. For example using the nullish coalescing operator (??) in a try catch statement could indicate that the device is below iOS 12.3. But this method also relies on running JavaScript directly on the client website or doing multiple requests.</p>
  <p>I would like to know if there are alternative methods we have not considered. Thanks.</p>