在 PyQt 应用程序中缓存 QtWebkit 小部件的外部 JavaScript

发布于 2024-09-26 11:34:37 字数 244 浏览 7 评论 0原文

我的应用程序中有一个 QWebView,它将存储在应用程序中的 html 页面呈现为 Qresource。然而,此页面需要丰富的外部 Javascript 库,例如 MathJax,由于其大小,我希望将其作为资源包含在内。

我的问题是,QtWebkit 似乎没有像常规浏览器那样缓存这些文件,每次我刷新小部件时,它都会重新下载 MathJax。

所以我的问题是:有没有办法在第一次下载这些库后缓存这些库,而不必将其作为资源与应用程序一起提供?

I have a QWebView in my app which renders a html page stored in the app as a Qresource. This page, however requires meaty external Javascript libraries such as MathJax, which I would want to include as a resource due to its size.

My problem is that it seems that QtWebkit does not cache these files as a regular browser would do, and every time I refresh the widget it downloads MathJax afresh.

So my question is: is there any way to cache these libraries after first time they are downloaded, without having resorting to shipping it with the app as resource?

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

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

发布评论

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

评论(2

安人多梦 2024-10-03 11:34:37

您应该尝试基于 QtNetwork 的简单下载是否遵循缓存设置。另外,请查看设置 (QWebSettings) 是否设置正确。

在所有情况下,您应该能够注入一个自定义 QNetworkAccessManager 来处理自定义 JS 库的缓存。请参阅http://ariya.blogspot.com/2010/05/qnetworkaccessmanager- tracenet-speed.htmlhttp:// /ariya.blogspot.com/2010/06/proxy-server-with-filtering-feature.html 作为示例并从那里跟进。

You should try if a simple QtNetwork-based download honor the cache setting or not. Also, see if the settings (QWebSettings) are set properly.

In all case, you should be able to inject a custom QNetworkAccessManager that handles the caching of your custom JS library. See http://ariya.blogspot.com/2010/05/qnetworkaccessmanager-tracenet-speed.html and http://ariya.blogspot.com/2010/06/proxy-server-with-filtering-feature.html as examples and follow it up from there.

抱着落日 2024-10-03 11:34:37

你能发布一些源代码吗?下载后,该数据将在 /tmp/ 文件夹中保留一段时间。您可能会使用临时文件夹中的数据,我的猜测是您没有执行该策略。

Could you post some source code? Once downloaded that data will stay in the /tmp/ folder for some time. You could likely use the data in the temp folder, my guess is you are not enforcing that policy.

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