Package, controller, addHeaderItem and caching…
Permalink
Hi folks,
I have a problem with a package I have developed for a custom block and I need your smart lights on that…
Step 1:
I had a problem with my controller and addHeaderItem() function. The javascript files were not loaded in the same order as the one defined in the block controller -> it created an error since some .js were dependencies of other ones.
Step 2:
The workaround: I removed the loading of the dependencies of the controller and put them directly in the view.php -> but since that, they were loaded twice: one time in the head of my page (it didn't take in account I have removed them from the controller) and one time in the body (the ones loaded in the view).
Step 3:
I have disabled all the caches, removed the files from the cache folder, cleared the cache, moved the site to an another hosting server (to be sure it isn't a server side caching) but it's driving me nuts… If I remove all the stuff from the on_page_view() controller function, it does nothing… except loading the javascript… very weird.
My Code:
The frontend result:
Any help would be greatly appreciated… Thank you in advance
Marc
I have a problem with a package I have developed for a custom block and I need your smart lights on that…
Step 1:
I had a problem with my controller and addHeaderItem() function. The javascript files were not loaded in the same order as the one defined in the block controller -> it created an error since some .js were dependencies of other ones.
Step 2:
The workaround: I removed the loading of the dependencies of the controller and put them directly in the view.php -> but since that, they were loaded twice: one time in the head of my page (it didn't take in account I have removed them from the controller) and one time in the body (the ones loaded in the view).
Step 3:
I have disabled all the caches, removed the files from the cache folder, cleared the cache, moved the site to an another hosting server (to be sure it isn't a server side caching) but it's driving me nuts… If I remove all the stuff from the on_page_view() controller function, it does nothing… except loading the javascript… very weird.
My Code:
public function on_page_view() { $html = Loader::helper('html'); $bv = new BlockView(); $bv->setBlockObject($this->getBlockObject()); $this->addHeaderItem($html->javascript($bv->getBlockURL() . '/js/day_price.js')); $this->addHeaderItem($html->javascript($bv->getBlockURL() . '/js/excanvas.min.js')); $this->addHeaderItem($html->javascript($bv->getBlockURL() . '/js/jquery.jqplot.min.js')); //$this->addHeaderItem($html->javascript($bv->getBlockURL() . '/js/jqplot.highlighter.min.js')); //$this->addHeaderItem($html->javascript($bv->getBlockURL() . '/js/jqplot.dateAxisRenderer.min.js')); …
The frontend result:
<script type="text/javascript" src="/metalcolor/packages/day_price/blocks/day_price/js/day_price_edit.js?v=84eb75194e91066ed8a4e682c0340868"></script> <script type="text/javascript" src="/metalcolor/packages/day_price/blocks/day_price/js/day_price.js?v=84eb75194e91066ed8a4e682c0340868"></script> <script type="text/javascript" src="/metalcolor/packages/day_price/blocks/day_price/js/excanvas.min.js?v=84eb75194e91066ed8a4e682c0340868"></script> <script type="text/javascript" src="/metalcolor/packages/day_price/blocks/day_price/js/jqplot.dateAxisRenderer.min.js?v=84eb75194e91066ed8a4e682c0340868"></script> <script type="text/javascript" src="/metalcolor/packages/day_price/blocks/day_price/js/jqplot.highlighter.min.js?v=84eb75194e91066ed8a4e682c0340868"></script> <script type="text/javascript" src="/metalcolor/packages/day_price/blocks/day_price/js/jquery.jqplot.min.js?v=84eb75194e91066ed8a4e682c0340868"></script>
Any help would be greatly appreciated… Thank you in advance
Marc
C5 will automatically load files in the block's /js folder, but in the order it finds them. So what it finds in the block's js folder is taking precedence over your own calls to addHeaderItem().
Solutions:
a) Combine them all into one file in the right order, and put that in the block's js folder. Remove all the addHeaderItem()calls.
b) Move all the script files into a folder that is not automatically loaded such as the package's /js folder, then change your addheaderItem() to load from there.
For most (if not all) of these, you can probably use addFooterItem() to improve page rendering.
Solutions:
a) Combine them all into one file in the right order, and put that in the block's js folder. Remove all the addHeaderItem()calls.
b) Move all the script files into a folder that is not automatically loaded such as the package's /js folder, then change your addheaderItem() to load from there.
For most (if not all) of these, you can probably use addFooterItem() to improve page rendering.
Thanks!
C5 forum members rock!
I have renamed the js in block_js and all my problems were gone with solution b)!
I will not use solution a) since I use plugins to draw graphics and I want to keep original files for a clear version tracking.
I have also change the addHeaderItems in addFooterItems to improve rendering.
Best reagards,
Marc
C5 forum members rock!
I have renamed the js in block_js and all my problems were gone with solution b)!
I will not use solution a) since I use plugins to draw graphics and I want to keep original files for a clear version tracking.
I have also change the addHeaderItems in addFooterItems to improve rendering.
Best reagards,
Marc
If you want you scripts to be loaded *after* something, you can use the addFooterItem (same syntax, but append the item at the end of the head tag).