开发者

Caching external javascript for a QtWebkit widget in a PyQt app

开发者 https://www.devze.com 2023-01-18 18:40 出处:网络
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

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?


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消