In drupal 6, I’ve written a module that outputs some html which I am displaying in a block using hook_block.
There is a js file that I want to load only when that block loads so I am drupal_add_js() inside hook_block.
It is all working except for this problem: when you refresh the page (regardless of whether you clear caches at the same time), often an old version of the script gets loaded. Newer and older versions turn up on a seemingly random basis.
What can I do to ensure that the correct version is loaded? Thanks.
Edit: One of the stylesheets that I’m loading via the theme’s .info file is doing the same thing – random versions of it are loading. So it looks like a general problem not module or block related.
Until youre satisfied with the javascript file, so that it may be locked down and used in cache, use the ‘defer’ and ‘cache’ arguments to drupal_add_js.
In admin > > performance you will find directives that includes js and css – if they’re deactivated, then one request is made per file added by drupal_add_*. If for instance js has preprocess set true, then all .info javascripts and scripts added by drupal_add_js will get sutured together into: one optimized deeply cached script
< 7.0
7.0 >
In your situation, if youre developing a script or need to push one fresh on every load, under all circumstances use false under
$cacheand$preprocess, so loading ‘main.js’ looks like:In v7+ func argv[1-X] would simply be put together in an associative array as
$options, see API