我如何避免重新提取残疾的CSS文件

发布于 2025-02-04 21:14:15 字数 377 浏览 2 评论 0原文

我正在尝试在我的网站上实现“黑暗主题”,目前通过包括2个样式表:

<link rel="stylesheet" type="text/css" href="/flatly.css">
<link rel="stylesheet" type="text/css" href="/darkly.css">

然后将“禁用”属性添加到Darkly CSS链接到Disable/Enable Dark主题。

这确实有效,但是每次我单击“启用”按钮时,提出了新的网络请求,以使Dark.css文件下载,这会导致恢复较小的滞后。

有人知道我如何解决这个问题吗?

I am trying to implement dark theme on my website and I currently do it by including 2 style sheets:

<link rel="stylesheet" type="text/css" href="/flatly.css">
<link rel="stylesheet" type="text/css" href="/darkly.css">

and then adding/removing the "disabled" attribute to the darkly css link to disable/enable dark theme.

This does work, but every time I click the enable button a new network request is made to download the darkly.css file, which causes a small lag in rerendering.

Does anyone know how I can get around this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

撞了怀 2025-02-11 21:14:16

检查您添加和删除残疾人属性的方式。使用纯JS,不要重新提取。

这个小小的 gist and gist运行此过程。

Check the way you are adding and removing the disabled property. Using pure JS, it's not to be re-fetching.

There's this little gist running this process.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文