Custom Block Scripts loading twice

Permalink
I've built a custom block and put it inside a package. Installs and works properly, however I have several js files in the /js directory of the block type. (package_name/blocks/block_name/js). These files are loaded automatically into the header whenever the block is added to the page. However, out of the 5 js files in the directory, 3 of them are loaded twice.

I've removed all the files and no scripts are loaded. Firebug tells me both instances of repeated scripts are being loaded from the same directory, so there are not other instances of the script being called from other places in the site.

I can't for the life of me figure out why they are being loaded twice.

Whenever the duplicates show up, something like /eval/seq/2 is appended to the URL of the first instance.

First Instance of one script:
<script type="text/javascript" src="/site_directory/packages/package_name/blocks/block_name/js/jquery.easing.1.3.min.js?v=8833856c29c7bce807c691be603bfb06"></script>


Second Instance of the same script:
<script type="text/javascript" src="/site_directory/packages/package_name/blocks/block_name/js/jquery.easing.1.3.min.js?v=8833856c29c7bce807c691be603bfb06/eval/seq/3"></script>


What's going on here?

 
PineCreativeLabs replied on at Permalink Reply
PineCreativeLabs
A good way to remedy this, is to define how the script is loaded on a page. Instead of using the default /js folder that Concrete automatically checks for, simply change that directory name to something like: /myblock-js/

Then, in the controller, add this code:

public function on_page_view() {
$html = Loader::helper('html');
$bv = new BlockView();
      $bv->setBlockObject($this->getBlockObject());
         $this->addHeaderItem($html->javascript($bv->getBlockURL().'/myblock-js/jquery.myscript.js'));
}

This forces the script to load from an explicitly defined directory.

I can't say for sure if this will solve your issue, but it has worked for me in the past.
jlego replied on at Permalink Reply
Hmm, I've added the on_page_view function to the block's controller as you suggested (and moved the scripts to a custom named folder of course) and they are still being loaded twice.

The funny thing is, its only 3 specific scripts. I had an additional 2 scripts in the original directory and they were not being duplicated. The same behavior occurs when moving all the scripts to a different directory and using addHeaderItem to add all of them. I can also leave the 2 no duplicating scripts in the /js directory while moving the duplicating 3 and calling them in the on_page_view() function and they are still loaded twice.

The scripts that are being duplicated are minified, while the 2 that aren't are not. Could this have something to do with it?