Use your time well

Welcome to my blog, I hope you will enjoy and you never deny to come back to visit again.
"USE YOUR FINGER TO CODE AND YOUR BRAIN TO THINK"


Search This Blog

Friday, October 17, 2014

How to minimize source code on including js files in Laravel master.blade

The best practice for any programmer is to make sure that his/her codes are minimized, readable and they are functioning.

But you need to use different trick to deal with that. For now I have one trick to include all files from the folder at once.


In the layout open master.blade.php and then look on the place you want to include your files and then add this codes

<!-- include the modalservice -->

            <?php
             $files = glob("{app/js/services/*.js}",GLOB_BRACE);

for($i = 0; $i < count($files); $i++){
?>
   <% HTML::script($files[$i]) %> 

<?php
}

?>
For best practice to know the format result of the variable $files, you can echo json_encode($files); to see the structure of the files then you will understand how does it functioning.

The above code will save the idea of having a lot of script to include, and even next time you add another script to the folder you don't need to include it again.