I am a beginner and am currently developing a kind of cms using PHP. The number of libraries that we can potentially use in the front end is large. I have a question about properly selecting, managing and using front end asset libraries.
I don't think just including a bunch of front end libraries like this is the best approach:
<script src="library1" /></script>
<script src="library2" /></script>
<script src="library3" /></script>
// and soon..
What if we use, let's say 20 ? Is that good practice, declaring the script tags 20 times ?
What I do currently is use Assetic
, a php library for managing assets. I create a dump file (and cache it) for each request to my application before loading a template. My controller (I use MVC) could be something like this:
function indexAction()
{
// some logic
$assetManager = $this->get('assetic'); // get assetic service
$css = $assetManager->createAsset(array(
'@bootstrap',
'@jquery_ui'
// and many other library
));
$assetContent = $css->dump();
// create asset url, dont mind about this
$data['stylesheet'] = $this->createAssetUrl($assetContent);
return $this->render('index-template', $data);
}
And in the template (index-template), I could put kind of:
<link href="<?php echo $stylesheet ?>" rel="stylesheet" type="text/css">
I do that in almost every controller to include a bunch of assets to view. But I am not sure if this is the best method. Are there any better practical method that I don't know ?