It is easy to check whether a client's browser supports service workers or not:
if('serviceWorker' in navigator) { // service worker available // lets code}
Here, I'll assume that a service worker is available in the user's browser, to avoid unnecessary code indentations every time.