What is the best method to enqueue scripts based on options I have? Let's say I have 50 options and for each I need to enqueue a script(some of them might repeat.). Can I have any problems(performance, etc.) if I do this in a foreach loop and switch to detect what script I need? Do you think is better than calling all scripts no matter what options I have? Like so(the class works just like I need):
<?php
class MyClass{
var $options;
public function __construct($options){
$this->options = ( isset($options) ) ? $options : array();
add_action( 'admin_enqueue_scripts', array(&$this, 'enqueue') );
}
//This is the section where I enqueue the scripts
function enqueue() {
foreach ($this->options as $value) {
switch ($value['type']) {
case 'value1':
wp_enqueue_script('value1_script');
break;
case 'value2':
wp_enqueue_script('value2_script');
break;
}
}
}
function render_opts() {
$output = '';
foreach ($this->options as $value) {
switch ($value['type']) {
case 'value1':
$output .= 'value1';
break;
case 'value2':
$output .= 'value2';
break;
}
}
return $output;
}
}
<script>tags, the page require 50 http requests to load and this will sure affect performance.