• home > tools > cloudServices > CDN >

    Cloudflare cache everything但音频和视频文件等并没有缓存

    Author:zhoulujun Date:

    Cloudflare 默认缓存不会缓存mp3 mp4等文件,即使pageRule 指定路径上配置的是cache everything,因为mp3 mp4 不被认为是static resources,需要增加pageRule设置

    今天有朋友告诉我,我的网站视频无法播放了,比如:https://www.zhoulujun.cn/html/about/trace/2018_1231_6452.html

    查了下,主机超载了。CDN没有缓存,所以CDN无法保活

    pageRule 配置的是 cache everything,怎么会没有缓存视频文件呢?

    Cloudflare 是不会像图片, js, css 等其它文件一下缓存音频和视频文件的

    The CloudFlare CND will cache the following static resources:

    css	bmp	tif	ttf	docx	woff2
    js	pict	tiff	eot	xlsx	 
    jpg	csv	eps	woff	xls	 
    jpeg	doc	ejs	otf	pptx	 
    gif	pdf	swf	svg	ps	 
    ico	pls	midi	svgz	class	 
    png	ppt	mid	webp	jar

    However, the media files such as *.mp3, *.mp4, *.avi etc can also be considered static resources, which can be embedded in HTML5 using audio or video tags. Caching these will enhance user’s experiences in listening to audio or watching a video on your site. In order to let cloudflare cache these static resources, you will need to create a page rule that caches everything, for example:

    mp3 mp4 不被认为是static resources,而不被默认缓存,需要缓存mp3 mp4 ,需要特别设置,添加pageRule

    微信截图_20200629111932.jpg


    拓展下

    If the setting is Cache Everything and no Edge Cache TTL is present, then the request will be disqualified, and it will not be cached. The Set-Cookie header will be stripped from the response that is sent to the client making the request.

    Even so, CloudFlare only caches files within reason so don’t use it to serve 1GB video files with this approach. For very large files like that, it’s better to use another network like Fastly, MaxCDN or CloudFront.

    Cloudflare limits upload size (HTTP POST request size) per plan type:

    • 100MB Free and Pro

    • 200MB Business

    • 500MB Enterprise by default (contact Customer Support to request a limit increase)

    If you require larger uploads, either:

    • chunk requests smaller than the upload thresholds, or

    • upload the full resource through a grey-clouded DNS record.

    具体看官网:https://support.cloudflare.com/hc/en-us/articles/200172516-What-file-extensions-does-CloudFlare-cache-for-static-content-


    _Figure 1: Always Cacheable File Extensions_

    class css jar js jpg jpeg gif ico png bmp pict csv doc docx xls xlsx ps pdf pls ppt pptx tif tiff ttf otf webp woff woff2 svg svgz eot eps ejs swf torrent midi mid

    _Figure 2: Sometimes Cacheable File Extensions_

    mp3 mp4 mp4v mpg mpeg mov mkv flv webm wmv avi ogg m4a wav aac ogv zip sit tar 7z rar rpm deb dmg iso img msi msp msm bin exe dll ra mka ts m4v asf mk3d rm swf 


    参考内容:

    How to Cache Audio/Video (*.mp4) using CloudFlare CDN? https://helloacm.com/how-to-cache-audiovideo-mp4-using-cloudflare-cdn/

    https://blog.cloudflare.com/understanding-our-cache-and-the-web-cache-deception-attack/




    转载本站文章《Cloudflare cache everything但音频和视频文件等并没有缓存》,
    请注明出处:https://www.zhoulujun.cn/html/tools/cloudServices/CDN/8492.html