1

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?

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

Comments

0

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.

3 Comments

Well the code is as plain as it can be, the widget is defined like this:: self.modelWebView = QtWebKit.QWebView(self.scrollAreaWidgetContents_2) and it loads a html document which loads some external js Using the data in /tmp/may not be a good idea since on other platforms (e.g. windows) the data may end up elsewhere.
sorry .. I should have said the (temp) directory, or said it some other way to imply I meant it as the temp folder regardless of OS. <br /><br />Because you are working from the basic class you will need to redefine how it it operates. One way to go about doing this is to turn all of your web pages into QWebElements before you navigate to them. The first time you load the page you can extract the script, save it as an object, and then re use it's contents from memory, inserting the script and local location as an element.
I wanted to add a second comment since I ran out of characters. The process is pretty simple and you can do it how you want. You download the script's source and create an object with it's contents and then use that locally. That is what I would suggest.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.