简体   繁体   English

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

[英]Caching external javascript for a QtWebkit widget in a PyQt app

I have a QWebView in my app which renders a html page stored in the app as a Qresource. 我的应用程序中有一个QWebView,它呈现一个存储在应用程序中的html页面作为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. 但是,此页面需要大量的外部Javascript库,例如MathJax,由于其大小,我希望将其作为资源包含在内。

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. 我的问题是QtWebkit似乎不像常规浏览器那样缓存这些文件,并且每次刷新小部件时,它都会重新下载MathJax。

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? 所以我的问题是:在第一次下载这些库之后,是否有任何方法可以缓存这些库,而不必借助应用程序作为资源来运送它?

You should try if a simple QtNetwork-based download honor the cache setting or not. 您应该尝试基于简单QtNetwork的下载是否符合缓存设置。 Also, see if the settings (QWebSettings) are set properly. 另外,请查看设置(QWebSettings)是否正确设置。

In all case, you should be able to inject a custom QNetworkAccessManager that handles the caching of your custom JS library. 在所有情况下,您都应该能够注入一个自定义QNetworkAccessManager来处理自定义JS库的缓存。 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. 参见http://ariya.blogspot.com/2010/05/qnetworkaccessmanager-tracenet-speed.htmlhttp://ariya.blogspot.com/2010/06/proxy-server-with-filtering-feature.html作为示例然后从那里跟进

Could you post some source code? 您可以发布一些源代码吗? Once downloaded that data will stay in the /tmp/ folder for some time. 下载后,该数据将在/ tmp /文件夹中保留一段时间。 You could likely use the data in the temp folder, my guess is you are not enforcing that policy. 您可能会使用temp文件夹中的数据,我想您不是要执行该策略。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM