From 8ff70ed6210fc7be673996d75227d83aea920bd6 Mon Sep 17 00:00:00 2001 From: LamGC Date: Tue, 13 Jun 2023 22:38:04 +0800 Subject: [PATCH] Add: Support instructing browsers to cache backgroundImage. By instructing the browser to allow caching of resources, it can significantly speed up the browser's loading of previous images (due to the use of hard disk caching). --- plugins/WebSocketDataSender/WebSocketDataGetter.cs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/plugins/WebSocketDataSender/WebSocketDataGetter.cs b/plugins/WebSocketDataSender/WebSocketDataGetter.cs index b17f3386..a3a11095 100644 --- a/plugins/WebSocketDataSender/WebSocketDataGetter.cs +++ b/plugins/WebSocketDataSender/WebSocketDataGetter.cs @@ -165,6 +165,10 @@ private async Task SendCurrentBeatmapImage(IHttpContext context) if (!File.Exists(location)) return; + bool.TryParse(context.Request.QueryString.Get("cache"), out var enableCache); + if (enableCache) + context.Response.Headers.Add("Cache-Control", "public, max-age=7200"); + await using var fs = new FileStream(location, FileMode.Open, FileAccess.Read); if (!(context.Request.QueryString.ContainsKey("width") || context.Request.QueryString.ContainsKey("height")))