Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Web and WebWorks Development

Reply
Highlighted
New Contributor
Posts: 7
Registered: ‎09-25-2012
My Device: BB10
My Carrier: n/a
Accepted Solution

<img> images not being cached in BB10 Webworks app

Hi,

 

Is there some configuration setting I need to use to get Webworks (on BB10) to cache images served from a server?

 

I have a BB10 Webworks application that dynamically adds and remove html from the DOM.  Images referenced in <img> elements load as expected, but if the element is removed from the DOM and, later, added in again, Webworks reloads the image file from the server rather than using a cached version.  (I can watch it happening in Web Inspector.)

 

If I run the code in a Chrome browser on Windows, it behaves properly, using the cached copy of the image when the new element is added to the DOM.

 

The HTTP Resonse headers from the server are:

 

Cache-ControlSmiley Tongueublic, must-revalidate
Content-Length:1730
Content-Type:image/jpeg
Date:Mon, 21 Oct 2013 21:18:34 GMT
ETag:c4863b363e4536f8d854d721092cf528
Expires:Wed, 20 Nov 2013 21:18:34 +0000
Last-Modified:Mon, 04 Feb 2013 17:20:13 +0000
MicrosoftOfficeWebServer:5.0_Pub
Server:Microsoft-IIS/6.0
X-Powered-BySmiley TongueHP/5.2.13, ASP.NET

 

So, with the Response codes above, Chrome caches the image as expected, while BB10 Webworks reloads it from the server each time (no caching).

 

I'm running on a Blackberry Z10, Model number STL100-3, Software Release 10.1.0.4181, and the app is created using Blackberry 10 Webworks SDK 1.0.4.11.

 

What am I missing?

 

Thanks,

Terry

 

Retired
Posts: 1,382
Registered: ‎07-02-2009
My Device: BlackBerry Bold 9900
My Carrier: Bell

Re: <img> images not being cached in BB10 Webworks app

Thanks for your question.  The WebView object used within a WebWorks application does not have its own cache system, like that which is built into a fully-featured browser.

 

For remove content loaded in a WebView, it will always be "fresh" content.

 

If you wish to embed static content in your app, it is suggested you package those files (e.g. Images, CSS or even JavaScript) that change infrequently directly in the BAR file.

 

Otherwise, I would recommend using something like HTML5 AppCache, or create your own caching system (e.g. to the file system or LocalStorage)

Follow me on Twitter: @n_adam_stanley
-------------------------------------------------------------------------------------------------------------------------
Your app doesn't work? Use BlackBerry remote web inspector to find out why.
Retired
Posts: 1,382
Registered: ‎07-02-2009
My Device: BlackBerry Bold 9900
My Carrier: Bell

Re: <img> images not being cached in BB10 Webworks app

It's been brought to my attention that there is in fact a way to enable caching in the webview using the following JavaScript&colon;

 

qnx.callExtensionMethod("webview.setEnableDiskCache", 0, "true"); 

 

However - there is a catch.  This is an unsupported API, that is mainly used by the platform but rarely by developers, and therefore is subject to change (but low likelihood).  I'd recommend using this technique at your own risk.

 

Follow me on Twitter: @n_adam_stanley
-------------------------------------------------------------------------------------------------------------------------
Your app doesn't work? Use BlackBerry remote web inspector to find out why.
New Contributor
Posts: 7
Registered: ‎09-25-2012
My Device: BB10
My Carrier: n/a

Re: <img> images not being cached in BB10 Webworks app

Adam,

 

Thanks for the reply.

 

I tried the javascript you provided but it reports "ReferenceError: Can't find variable: qnx".  Is there some other javascript file I need to include (other than local:///chrome/webworks.js)?

 

Terry

Retired
Posts: 1,382
Registered: ‎07-02-2009
My Device: BlackBerry Bold 9900
My Carrier: Bell

Re: <img> images not being cached in BB10 Webworks app

Apologies for the confusion.  The qnx object is only available in the context of a native extension running inside of the app - not directly from JavaScript running in your app.

 

Here is an example of an extension that uses the qnx object:

https://github.com/blackberry/WebWorks-Community-APIs/tree/master/BB10/PreventSleep

 

Specific location where it is being used:

https://github.com/blackberry/WebWorks-Community-APIs/blob/master/BB10/PreventSleep/ext/community.pr...

 

 

What is your comfort level writing / using native extensions?  You would have to craft your own, to interact with this API.

Follow me on Twitter: @n_adam_stanley
-------------------------------------------------------------------------------------------------------------------------
Your app doesn't work? Use BlackBerry remote web inspector to find out why.
New Contributor
Posts: 7
Registered: ‎09-25-2012
My Device: BB10
My Carrier: n/a

Re: <img> images not being cached in BB10 Webworks app

Adam,

 

That's disappointing.  I am porting an app to webworks that I already have running on Android and iOS under phonegap.  Webview caching just works on those systems.  I tried to use phonegap for BB10, but ran into enough problems that I decided to try webworks directly.

 

I've no experience at all with bb native extensions.

 

Do you know if phonegap/cordova for BB10 supports webview caching?

 

Terry

 

 

Retired
Posts: 203
Registered: ‎12-18-2012
My Device: Z10, Q10, Q5, Z30, Z3
My Carrier: Bell

Re: <img> images not being cached in BB10 Webworks app

Hi,

 

I've logged an issue with Apache to add this feature to cordova.

 

https://issues.apache.org/jira/browse/CB-5212

Bryan Higgins
BlackBerry WebWorks
@bryanhiggins
New Contributor
Posts: 7
Registered: ‎09-25-2012
My Device: BB10
My Carrier: n/a

Re: <img> images not being cached in BB10 Webworks app

Bryan,

 

Thanks for looking into this.

 

You might like to know that the cordova instructions for deploying apps to blackberry10 don't seem not work.  I have tried to deploy the cordova demo app following the steps shown at http://docs.phonegap.com/en/edge/guide_platforms_blackberry10_index.md.html#BlackBerry%2010%20Platfo... but the scripts crash.  I can run the corresponding scripts for android and iOS with no problems.  I've tried to debug their bb10 scripts, but to no avail.  (It appears to me that they have never been tested!)

 

There is a thread on stackoverflow at http://stackoverflow.com/questions/19315236/adding-blackberry10-platform-in-cordova3-0-0-is-showing-... that shows others are having the same problem with cordova and blackberry10.

 

 

Do you have any suggestions for that would help me deploy to bb10, or can you point me to a better set of instructions?

 

Any help would be appreciated.

 

Thanks,

Terry

 

Retired
Posts: 203
Registered: ‎12-18-2012
My Device: Z10, Q10, Q5, Z30, Z3
My Carrier: Bell

Re: <img> images not being cached in BB10 Webworks app

Hi,

 

The issue you described was reported on some WIndows systems and has since been fixed. It will be available in cordova 3.2, which is scheduled to be released early next month.

 

It is a relatively simple fix which you could apply to platforms/blackberry10/cordova/init.bat

 

https://github.com/apache/cordova-blackberry/commit/f9327e0ac00f30c36aef95dd003888b5f6ffa981

Bryan Higgins
BlackBerry WebWorks
@bryanhiggins
New Contributor
Posts: 7
Registered: ‎09-25-2012
My Device: BB10
My Carrier: n/a

Re: <img> images not being cached in BB10 Webworks app

Bryan,

 

Thanks for that fix.  Unfortunately, it didn't work for me.  I changed init.bat as indicated, but I still get the same message that "node cannot be found in path".

 

My bat-file skills are rusty, but I fiddled with the init.bat file some more and it appears that the SET command is not behaving as I would have expected.  After the line (approx line 34):

 

set FOUNDNODE=%%~$PATH:X

 

I added the line:


ECHO setting FOUNDNODE=[%FOUNDNODE%] [%%~$PATH:X]

 

the output shows 

 

setting FOUNDNODE=[] []

setting FOUNDNODE=[] [C:\Program Files\nodejs\node.exe]

 

It seems that FOUNDNODE is getting set to some empty value rather than the proper path value.  I'm running Windows 7(x64).

 

As I said, my bat-file skills are rusty, but have you ever seen something like this before?

 

Terry