javascript - Client keeps requesting file from REST API -
i have audio file stored on server , clients can request these audio files via rest api. observed data requested client , came conclusion whenever play audio again (repeat), new request goes server specific file. there way prevent or cache data locally?
html
<audio controls="controls" autoplay style="width: 100%"> <source src="https://localhost:8080/api/file" type="audio/mpeg"> </audio>
javascript (node.js in combination express.js)
router.get('/file', (req, res) => { let audiofile = path.join(__dirname, 'files/audio-book.mp3'); res.sendfile(audiofile); })
edit
i have local file , file sent rest api. local file request has http code 304: not modified
, file rest api request 206: partial content
. added max-age
, removed last-modified
, no result.
headers:
accept-ranges -> bytes cache-control -> public, max-age=3600 connection -> keep-alive content-length -> 7056954 content-type -> audio/mpeg date -> sun, 17 jan 2016 10:16:48 gmt etag -> w/"6bae3a-15195a7f2aa" x-powered-by → express
situation
what happened browser wouldn't cache file in way, shape or form. let tremendous amounts of traffic.
solution
i found this article on stackoverflow requesting files in blobs , letting audio- or video element play it. xhr file server , store in blob , when replay audio, retrieves data cache , can work offline now.
Comments
Post a Comment