开发者

Forcing user's browser to save files to cache

My website is a online music portal with online playing system.

When user play a song, it is served by nginx server on port 8080 on my server.

The problem is when the song has finished playing, the player repeats the song. But every time it replays, it makes another call to se开发者_如何转开发rver and starts downloading the file again to play.

Previously i had apache to serve these files. At that time, user just requested file once and replays were played from his cache. How can i achieve this using nginx

[I am not using any script like php or so to serve the file. It's just direct link. Like http://www.myserver.com:8080/music/song1.mp3]


It would help a lot to see some of your former Apache configuration and current Nginx configuration to see how they're set up to put expiration headers on outbound files. This isn't a foolproof way to enforce caching, as you may know, but it sounds like "good enough" will work for you. Try an Nginx configuration block within your server{} block which reads like this:

location ~* \.(mp3)$ {
    expires max;
}

That should set a far-future expiration date on your files and encourage the browser to cache them longer.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜