简体   繁体   中英

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,

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?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM