Use HtmlHelper::script
If you use HtmlHelper::script method, with 'inline' => false
, to load the js files they will by default be included once.
Layout file
To use this method, ensure that in the layout file the $scripts_for_layout
variable is echoed out. E.g.:
<html>
<head>
...
</head>
<body>
...
<?php echo $scripts_for_layout ?>
</body>
</html>
View files
In your views, elements or helpers - simply ensure the script method is called using the inline parameter:
<?php $this->Html->script('my', array('inline' => false)); ?>
In this way it doesn't matter how often you call the script method with a given js file - it will appear in the resultant html output only once.