if ('serviceWorker' in navigator) {
    navigator.serviceWorker.register('/sw.js');
};

Annotation

Nice guide going over service workers.