浏览器通过php查询字符串缓存图像和视频 [英] Browser Caching of images and videos served via php query strings

查看:105
本文介绍了浏览器通过php查询字符串缓存图像和视频的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在建立一个网站,要求用户登录才能访问任何内容,因此所有视频和图像资产都通过对php文件的请求来提供,例如:

I'm making a website that requires users to be logged in to access anything, thus all video and image assets are served via requests to a php file, like:

example.com/media/?clip=668&q=h 服务器检查是否允许该用户,如果允许,则返回一个mp4文件,"q = h"表示我想要半分辨率视频"

example.com/media/?clip=668&q=h the server checks to see the user is allowed, and if so, responds with a mp4 file, "q=h" meaning "i want the half-res video"

example.com/media/?clip=668&q=t 回复一个jpeg文件,"q = t"表示我想要缩略图"

and example.com/media/?clip=668&q=t responds with a jpeg file, "q=t" meaning "i want the thumbnail"

在我的网站上一切正常,我已经设置了mime类型和所有内容.但是,Chrome永远不会缓存任何这些资产,因此我的带宽在飞速增长.在Chrome Inspector的网络"标签中,我的css和js文件来自(来自内存缓存)"或(来自浏览器缓存)",但是我所有的重资产(图像和视频)都没有缓存.

it all works well enough on my site, i've got the mime types and everything set. however, Chrome never caches any of these assets, so my bandwidth is skyrocketing. in the Network tab of Chrome Inspector, my css and js files come "(from memory cache)" or "(from browser cache)", but all my heavy assets, the images and videos, don't cache.

我如何让浏览器缓存这些内容?

how can i get the browser to cache these?

推荐答案

感谢@tim!

问题出在我与媒体一起提供的标题中.我在Chrome浏览器中查看了响应,并说:

The problem was in the headers i was serving alongside my media. I looked at the response in Chrome and it said:

Cache-Control: must-revalidate, no-cache, no-store

我没有设置这些,它必须是apache的默认值,因为我正在通过脚本提供服务?无论如何,要修复,我只是添加了:

I didn't set these, it must be a default of apache since I'm serving through a script? Anyways, to fix, I just added:

Cache-Control: public

到我的PHP文件,它似乎正在工作!

to my PHP file and it seems to be working!

这篇关于浏览器通过php查询字符串缓存图像和视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆