Project

General

Profile

HTML - caching jquery and css files on the client

Added by Peter K over 11 years ago

Hi everyone,

Is there a simple way to make sure that Wt caches rarely changing files on the client, such as jquery.js? I am using the WtHttp connector (with SSL enabled, if that matters...) Currently, jquery gets downloaded on every page refresh. Is that the default behavior?

Thanks in advance,

Peter


Replies (4)

RE: HTML - caching jquery and css files on the client - Added by Koen Deforche over 11 years ago

Hey Peter,

What's happening is that JQuery is downloaded for every new session (or page refresh), inline with Wt's scripting code. The underlying assumption is that this is fine for sessions that are long-lived (i.e. when typically 10, 100 or thousands or events happen within a session) and that's really what Wt has been designed for: actual applications.

Caching is important for full-page applications because every event potentially requests the same resources over and over within a single 'session'; it's much less important for the longer term as studies have shown that most people will come with an evicted cache anyway to your site, even after .

Is your use case so different then?

Regards,

koen

RE: HTML - caching jquery and css files on the client - Added by Peter K over 11 years ago

Hi Koen,

I see! That makes a lot of sense. My problem is that the user frequently navigates away from my application page by clicking on a link, and then presses the "back" browser button to return to my page. Which causes a new session to be created... Basically, the application is a search engine, so I was kind of expecting that there would be a lot of new sessions, with users coming and going from my page multiple times.

I understand that I could open the new links in a new window, which will help. But I thought that maybe there is some trick to get the browser to cache the files...

For example, what if I call requireJQuery("") and point it to jquery.js on Google's CDN network, would that result in a different caching behavior in the browser?

Thank you,

Peter

RE: HTML - caching jquery and css files on the client - Added by Koen Deforche over 11 years ago

Hey,

Using requireJQuery and pointing to Google's CDN will indeed cause the JQuery file to be cached.

There is however another big piece of JavaScript 'library' that we include which is Wt's own support library. It is however not a completely static file, but it probably could be changed so that it is.

If you're building a kind of search engine, you already using progressive bootstrap which at least makes the contents available without needing to wait for the JavaScript?

Regards,

koen

RE: HTML - caching jquery and css files on the client - Added by Peter K over 11 years ago

Progressive bootstrap is enabled in wt_config.xml, right? For some reason I can't use wt_config.xml at all... I get a crash whenever I call setServerConfiguration() with a non-empty config file name, for example:

int argc=5;

char* argv[]={"blah","---http-address=0.0.0.0","---http-port=80","---deploy-path=/","---docroot=."};

server.setServerConfiguration(argc, argv, "c:/witty/wt_config.xml"); -> Crash, even when wt_config.xml is not modified after Wt install.

server.setServerConfiguration(argc, argv, "");-> OK

This is on Wt 3.3.1. Is it something that you can reproduce?

Thank you,

Peter

    (1-4/4)