Eder
Eder

Reputation: 1884

Javascript: Is Javascript cached if invoked from the html's body?

Problem!

I am calling a JS function inside the html's body section, the function's parameters are gathered by parsing the EL inside the function.

Eg:

<script type="text/javascript">
    jQuery(window).load(function() {
        loadImage("${expression_language_var_1}", "${expression_language_var2}");
    });
</script>

But it seems that sometimes both parameters are cached and I do receive old information.

Questions!

Best Regards,

Upvotes: 3

Views: 141

Answers (1)

stealthwang
stealthwang

Reputation: 954

The issue is that the entire HTML page is being cached, including the script tags which contain your evaluated EL. If you serve the page with the following header tags the browser shouldn't cache it:

<meta http-equiv="cache-control" content="max-age=0" />
<meta http-equiv="cache-control" content="no-cache" />
<meta http-equiv="expires" content="0" />
<meta http-equiv="expires" content="Tue, 01 Jan 1980 1:00:00 GMT" />
<meta http-equiv="pragma" content="no-cache" />

For more details about how these headers disable caching refer to this answer: Using <meta> tags to turn off caching in all browsers?

Upvotes: 1

Related Questions