JS minify not working
adeelmughal4u opened this issue · comments
$menu = 'mmenu.min.js';
$tippy = 'tippy.all.min.js';
$simplebar = 'simplebar.min.js';
$bootstrap_slider = 'bootstrap-slider.min.js';
$simplebar_select = 'bootstrap-select.min.js';
$snackbar = 'snackbar.js';
$clipboard = 'clipboard.min.js';
$counterup = 'counterup.min.js';
$magnific = 'magnific-popup.min.js';
$slick = 'slick.min.js';
$custom = 'custom.js';
$all_js = array($menu,$tippy,$simplebar,$bootstrap_slider,$simplebar_select,$snackbar,$clipboard,$counterup,$magnific,$slick,$custom);
$this->minify->js($all_js);
echo $this->minify->deploy_js();
I was not able to reproduce this issue.
- What compression engine are you using (did you try to change it)?
- What is your PHP version?
- What CodeIgniter version are you using?
My php version is 7.2 and CI 3
CSS is working fine but JS not working... how I can change compression engine?
Search for $config['compression_engine']
in application/config/minify.php
file.
OR
Dynamically, in your code - before using deploy_js
method: $this->minify->compression_engine['js'] = 'jsmin'
(or jsminplus).
I'm not sure but closurecompiler
engine may have some limitation for POST request. And it seems that you're trying to send a lot of data.
Yes I am sending 6,7 files with a lot of code, should I compress it in 2, 3 files in chunks... BTW thanks a lot for helping 👍
Does other compression engines fails too? Your result file is empty or not? You can try with: $this->minify->deploy_js(TRUE)
If this is happening only for closurecompiler
(default) engine, I would test it by adding to js()
method only one file and then another, and another... then you will see if this is a problem with too big request or is it something with your js files.
Files in chunks... You could create a groups of files by calling:
$this->minify->js($files_array, 'group_number_here')
and then deploy as usual. Every group will send separate request to closurecompiler.
Yes, my result file is empty but I am trying to do by your way as you explained and update you.
$this->minify->js($all_js,'v-1.0.0');
$this->minify->compression_engine['js'] = 'jsmin';
echo $this->minify->deploy_js(TRUE);
with above code file is generating and everything fine... but not working with "jsminplus"
Ok, I tested it out.
- "jsminplus" don't handle new js syntax well, e.g. using "let" instead of "var" cause error - but we have info on the screen what is happening so I guess it's ok.
- "closurecompiler" fails silently when there is any error - but this one is fixed now (#59).
In your case almost every js file is already minified, so you can save some time and just skip compression for this files.
$this->minify->auto_names = TRUE;
// disable compression
$this->minify->compress = FALSE;
$no_compress = ['mmenu.min.js', 'tippy.all.min.js', 'simplebar.min.js', 'bootstrap-slider.min.js', 'bootstrap-select.min.js', 'clipboard.min.js', 'counterup.min.js', 'magnific-popup.min.js', 'slick.min.js'];
$this->minify->js($no_compress, 'merge');
echo $this->minify->deploy_js(FALSE, NULL, 'merge');
// enable compression
$this->minify->compress = TRUE;
$compress = ['snackbar.js', 'custom.js'];
$this->minify->js($compress, 'default');
echo $this->minify->deploy_js(FALSE, NULL, 'default');
Yes, that's good.
but I have another suggestion, by using this compression, a new file generated right. and when we made any change in any of the css or js file... the compressed file is auto updated it which causing the website process slowdown while generating and loading new file.
Instead of generating new file each time when we made changes in file... there should be a version controlling system where from we can generate the new file by changing the version otherwise the old generated file should be used even if there is a new change in CSS file.
Yes... good thought. Done (#60).
Replace auto names ($this->minify->auto_names = TRUE;
) from my previous comment with:
$this->minify->versioning = TRUE;
$this->minify->deploy_on_change = FALSE;
and then create separate controller/method (e.g. assets/deploy
), that will force assets deploy. Something like:
// Assets controller
public function deploy()
{
$this->load->library('minify');
// disable compression
$this->minify->compress = FALSE;
$no_compress = ['mmenu.min.js', 'tippy.all.min.js', 'simplebar.min.js', 'bootstrap-slider.min.js', 'bootstrap-select.min.js', 'clipboard.min.js', 'counterup.min.js', 'magnific-popup.min.js', 'slick.min.js'];
$this->minify->js($no_compress, 'merge');
// force deploy
$this->minify->deploy_js(TRUE, NULL, 'merge');
// enable compression
$this->minify->compress = TRUE;
$compress = ['snackbar.js', 'custom.js'];
$this->minify->js($compress, 'default');
// force deploy
$this->minify->deploy_js(TRUE, NULL, 'default');
}
And call this every time you want to generate a new assets versions.
It's working fine... 👍 I used it for my project.