Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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!

  • Are the script tags inside the html structure being cached just the same way as the external javascript files that are included in the header?

Best Regards,

like image 216
Eder Avatar asked Jul 16 '26 12:07

Eder


1 Answers

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?

like image 54
stealthwang Avatar answered Jul 18 '26 01:07

stealthwang



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!