CodeIgniter Forums
Merge .js files to load only "single merged maxi one" - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: General (https://forum.codeigniter.com/forumdisplay.php?fid=1)
+--- Forum: Lounge (https://forum.codeigniter.com/forumdisplay.php?fid=3)
+--- Thread: Merge .js files to load only "single merged maxi one" (/showthread.php?tid=69567)



Merge .js files to load only "single merged maxi one" - ldetomi - 12-15-2017

Hi,
I don't know if is the right section but here my problem:

Currently I have many many .js files loaded at startup (often small ones but is useful mantain them separated for better organization and maintenance).

In some enterprise platform like LifeRay, is possibile to have a maxi merged-file or load them separated (for debug purposes) simply adding an option to URL like "?js_fast_load=0".

Apart url parameter.... is maybe possible with CodeIgniter to have a feature like this or maybe you have some other suggestions to mantain separated source code, but load in PROD env only a merged one for performances?

Thank you


RE: Merge .js files to load only "single merged maxi one" - Wouter60 - 12-15-2017

You can use 2 differente templates. One for the development environment, and one for production.
E.g.:

template_dev.php:
PHP Code:
$this->load->view('template/header_dev');
$this->load->view($main_view);
$this->load->view('template/footer_dev'); 

template_prod.php:
PHP Code:
$this->load->view('template/header_prod');
$this->load->view($main_view);
$this->load->view('template/footer_prod'); 

In your controller, you do this:
PHP Code:
$data['main_view'] = 'the_view';
if (
ENVIRONMENT == 'production') {
 
  $this->load->view('template/template_prod',$data);
}
else {
 
  $this->load->view('template/template_dev',$data);


The header_prod.php file must load the merged js file. The header_dev.php file must load the js files separately.


RE: Merge .js files to load only "single merged maxi one" - ldetomi - 12-18-2017

(12-15-2017, 10:52 AM)Wouter60 Wrote: You can use 2 differente templates. One for the development environment, and one for production.
E.g.:

template_dev.php:
PHP Code:
$this->load->view('template/header_dev');
$this->load->view($main_view);
$this->load->view('template/footer_dev'); 

template_prod.php:
PHP Code:
$this->load->view('template/header_prod');
$this->load->view($main_view);
$this->load->view('template/footer_prod'); 

In your controller, you do this:
PHP Code:
$data['main_view'] = 'the_view';
if (
ENVIRONMENT == 'production') {
 
  $this->load->view('template/template_prod',$data);
}
else {
 
  $this->load->view('template/template_dev',$data);


The header_prod.php file must load the merged js file. The header_dev.php file must load the js files separately.

Yes, thanks... but my issue is "how to auto-merge these files?". As I said, there are several enterprise platoform that do this kind of task beyond load different files