The simpliest way is to play (stream) the music file using <audio> tag, the resource would be cached once you have completed the playback once. Then you can go offline and start looping.
I think you could use the CacheStorage[0] framework for this, but IIRC it's not got a great size per domain and is limited by a varying amount of 5MB to 100MB depending on browser.
It looks like Firefox may be different in this regard. Chrome[0] and Edge[1] allow `unlimitedStorage` to be specified that removes the 5MB default limit.