slav123 / codeigniter-minify Goto Github PK
View Code? Open in Web Editor NEWCodeIgniter minify library CSS and JavaScript compression on the fly
License: MIT License
CodeIgniter minify library CSS and JavaScript compression on the fly
License: MIT License
If a JS file has a //comment on the last line (without any newline after), the concatenated code is wrong, causing errors of the js compiler.
I'm submitting a pull request to fix this bug by appending a newline after the contents of each file.
Hopefully there is a better solution.
Hi! Just a minor annoying issue... but if one creates, for example, three groups of css and/or js files named "head", "body" and "foot" by issuing:
$this->minify->js(["one.js", "two.js"], "head");
$this->minify->js(["three.css", "four.js"], "body");
$this->minify->js(["five.js"], "foot");
and deploy every one via:
echo $this->minify->deploy_js(ENVIRONMENT !== 'production', NULL, 'head');
echo $this->minify->deploy_js(ENVIRONMENT !== 'production', NULL, 'body');
echo $this->minify->deploy_js(ENVIRONMENT !== 'production', NULL, 'foot');
Than the generated names will be concatenated like this:
head_scripts.min.js
body_head_scripts.min.js
foot_body_head_scripts.min.js
I don't know if that is the author intention, but I think the final names should be:
head_scripts.min.js
body_scripts.min.js
foot_scripts.min.js
Regards.
In my development area i've tested the output on all files i need to combine and minify, but on multiple files it seems to slow down to about 3 sec.
Does this library offer some sort of cache option to only allow recombine after a period of time so the speed stays optimized or do i need to just download the file and inlcude it manualy?
hi
Is it possible to look for js or css files in more than one location how to specify in minify.php config
(where to look for js files (default value: 'assets/js'))
Hi all,
I tried to use the library and I was able to generate minified files for CSS and JS, but then I realized that the browser is not caching them and every time it was fetching these files from the server.
Is there any way we can use the browser cache functionality along with this library.
Thanks.
Need to change ClosureCompiler as the default to jsmin or just remove ClosureCompiler.js as it isn't supported? Unless the main author gave the project to some one else it appears to be archived.
Hi there,first of all thanks for this awesome library.
Can we select multiple directories?
ie. Separated files for back-end and front-end?
I'm using this code
$this->load->library('minify'); $minify_config['js_file'] = 'newtable.js'; $minify = new Minify($minify_config); $minify->js(array('tables.js'));
I want my own name of js_file, but they return me alway the same js name file: script.min.js
I'm using PHP7.2
Unable to load the requested class "minify" . . . i'm use load->library
//my minify library path is application/libraries/Minify
$this->load->library('minify');
How about no scan files in dir or no check file mod.
I think i am missing something.
The script.min.js is created but its empty
I have used a couple of js and css under compression on local server and tested it at Google Page Speed tool.
Now there is a server response delay of 4 sec. Any chance, I can reduce it to the min?
My code:
$this->minify->add_js(['1.js','2.js','3.js','4.js','5.js','6.js','7.js'], 'essentials_javascript');
$this->minify->deploy_js();
Hi, it`s possible to use my static_url instead a base_url?
"compression_engine" works like a charm! Can we obfuscate div ids or classes name as well and put it back to html page. For e.g.
--------------------Input--------------------------
..... css file ....
#hi{
color:black;
}
.test{
font-size:1rem;
}
-------------------Output--------------------------
..... css file ....
#0typs_123{ color:black;}.lpsd{font-size:1rem;}
Edited
Hello,
is there a way to cache the output files? or it's already cached by this library?
Hi.
Have a problem with config
$config['compression_engine']['js'] = 'closurecompiler';
The compiled file is empty.
'jsminplus' doesn't work too.
Thanks
I am adding this code to footer
if ( isset( $this->minify ) ) {
$this->minify->add_js( [ 'profile.questions.load_more.js', 'question.comments.load_more.js' ] );
echo $this->minify->deploy_js( true, 'auto' );
}
it is working fine on localhost but when I am deploying to production, it is converting domain to IP.
I want: http://localhost/assets/1c4a7deccc90cfe0629ecaba41da0dbe.min.js
Minify converting to http://127.0.0.1/assets/1c4a7deccc90cfe0629ecaba41da0dbe.min.js
Using along with CodeIgniter.
Minify version : latest
Is there any options not to combine some of the css or js?
In total, i have 4 js files and i would like to make 2 different groups of 2 js each with compression. The current deploy_js adds the rest of two in previous compressed two.
$this->minify->add_js('pace.min.js')->add_js('animsition.min.js');
echo $this->minify->deploy_js();
$this->minify->add_js('scrollreveal.min.js')->add_js('footer.js');
echo $this->minify->deploy_js();
Any thought?
Hello,
When merging multiple JS files, if one of them do not finish with a semicolon, it may cause a javascript error.
To avoid this, we have to add a semicolon at the end of every js files.
Maybe it could be done automatically.
Seb
@slav123 thanks for this nice library. :)
when i try it the apache always crashed when rebuild minify JS or CSS or both. have been googling for a while and found a solution. it work for me.
edit http.conf and add this line.
ThreadStackSize 8388608more detailed about this issue: https://code.google.com/p/minify/issues/detail?id=62#c9
Hi
My problem is that in my project, every time the page loads, the library runs and re-compresses the files.
This will cause heavy loading.
How to set it to run once every 3 days, for example.
Or just run again in case of changes?
Now how I understood return only with HTML TAG.
// return '<script type="text/javascript" src="' . base_url($this->_js_file) . '"></script>';
Some times css empty but after page refreshing its working
Please provide solution on it.
With closure compiler have a issue related to limit of requesting method in an hours.
you have any solution related to this problem. please share with me.
Thanks
I liked your library, but it lacks support to retrieving content from external sites like CDNs. The idea is to add a function to store the content of an assets with cURL and write it compressed to the unified css/js file.
there is error happened some time with first visit (no cached) css_new.min.css empty but after refresh page it's work fine
check this link:
https://mob4me.com/%D8%B3%D8%A7%D9%85%D8%B3%D9%88%D9%86%D8%AC/
Following will cause the css minifier to fail silently:
.table > thead > tr > th,
data: {
customer_email: customer_email,
customer_firstname: customer_firstname,
}
Last colon is an error, but jQuery skip that with no issue.
The minifier returns an empty script when it founds that.
When the minifier detects on the array of files a file modified after the last time, it generates the resulting script, it generates a new one. It rocks. But...
When you add to the array of files a new file wich its last modified date is previous to the resulting script modified date, it does not generates a new one.
$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();
Inside _scan_files() you can filter out any cachebusting on the files.
for example, some would use /style.css?version=1
this creates an error so you'll want to discard anything after ?
something like:
$filename = $directory . '/' . preg_replace('#\?.*#', '', $file);
You find this again inside _concat_files()
$file_name = $directory . '/' . preg_replace('#\?.*#', '', $file_name);
You should strip all the filenames entered into Minify.
Nothing serious, but I get a double slash after the base url, like http://www.example.com//assets/script.min.js
.
Am I doing something wrong? Configuration is like explained in the example:
$config['assets_dir'] = 'assets';
$config['css_dir'] = 'assets/css';
$config['js_dir'] = 'assets/js';
I guess the second slash is from Minify#deploy_js:384
return "<script type=\"text/javascript\" src=\"" . base_url() . '/' . $this->js_file . "\"></script>";
CI config.php states the base URL comes with a trailing slash, so the one separator after base_url()
is the second one.
/*
|--------------------------------------------------------------------------
| Base Site URL
|--------------------------------------------------------------------------
|
| URL to your CodeIgniter root. Typically this will be your base URL,
| WITH a trailing slash:
|
| http://example.com/
|
| If this is not set then CodeIgniter will guess the protocol, domain and
| path to your installation.
|
*/
When I develop an application, I often reload the script data, but the "filesize" function in "linux" has a cache. Subsequently, files are not generated until the end.
Add before
clearstatcache();
$contents = fread($handle, filesize($out_file));
Sometimes one wants to switch off the minification but keep the cache busting/versioning on the output.
in _simple_output()
foreach ($files as $file)
{
$filename = $directory . '/' . $file;
if ($this->versioning)
{
$filename .= '?v=' . md5_file($filename);
}
$output[] = $filename;
}
I'm testing your library with your example css and js files and when it generate the minified files I get this errors but the files are correctly generated.
I'm working with codeigniter 2.2.0.
A PHP Error was encountered
Severity: Notice
Message: Undefined index: css
Filename: libraries/Minify.php
Line Number: 224
A PHP Error was encountered
Severity: Notice
Message: Undefined index: css
Filename: libraries/Minify.php
Line Number: 224
A PHP Error was encountered
Severity: Notice
Message: Undefined index: js
Filename: libraries/Minify.php
Line Number: 224
A PHP Error was encountered
Severity: Notice
Message: Undefined index: js
Filename: libraries/Minify.php
Line Number: 224
Hi,
First of all, I really appreciate the effort you put in this GIT project to help us all make CI faster.
Currently i'm working with CI4 to see if my application is compatible, but in CI3 i'm using your minifier.
Do you have plans on creating this for CI4 also?
Kind regards,
A PHP Error was encountered
Severity: Warning
Message: touch(): Unable to create file assets/styles.min.css because No such file or directory
Filename: libraries/Minify.php
Line Number: 450
Hi,
First of all thanks for your contribution, this library is really awesome. However, I am facing a very tiny issue which I hope you can rectify in sometime. I changed the css minify library to "cssmin" but, I got the following error.
Thank you!
**A PHP Error was encountered
Severity: 8192
Message: The each() function is deprecated. This message will be suppressed on further calls
Filename: Minify/cssmin-v3.0.1.php
Line Number: 2222
Backtrace:
File: C:\xampp\htdocs\sites\lakhina-couture\application\libraries\Minify\cssmin-v3.0.1.php
Line: 2222
Function: each
File: C:\xampp\htdocs\sites\lakhina-couture\application\libraries\Minify\cssmin-v3.0.1.php
Line: 2315
Function: initialise
File: C:\xampp\htdocs\sites\lakhina-couture\application\libraries\Minify.php
Line: 715
Function: require_once
File: C:\xampp\htdocs\sites\lakhina-couture\application\libraries\Minify.php
Line: 650
Function: _cssmin
File: C:\xampp\htdocs\sites\lakhina-couture\application\libraries\Minify.php
Line: 537
Function: _concat_files
File: C:\xampp\htdocs\sites\lakhina-couture\application\libraries\Minify.php
Line: 394
Function: _scan_files
File: C:\xampp\htdocs\sites\lakhina-couture\application\libraries\Minify.php
Line: 330
Function: _deploy_css
File: C:\xampp\htdocs\sites\lakhina-couture\application\controllers\Deploy.php
Line: 20
Function: deploy_css
File: C:\xampp\htdocs\sites\lakhina-couture\application\controllers\Deploy.php
Line: 12
Function: _minify_backend
File: C:\xampp\htdocs\sites\lakhina-couture\index.php
Line: 273
Function: require_once**
Using $config['base_url'] in the default config.php will cause malformed generated URLs.
Example:
$config['base_url'] = 'https://example.com/';
Results:
<script type="text/javascript" src="https://example.com/https://example.com/assets/scripts.min.js"></script>
Please change it
private function _closurecompiler($data) {
on
private function _closurecompiler($data) { $config = $this->closurecompiler; $ch = curl_init('https://closure-compiler.appspot.com/compile'); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, 'output_info=compiled_code&output_format=text&compilation_level=' . $config['compilation_level'] . '&js_code=' . urlencode($data)); $output = curl_exec($ch); curl_close($ch); return $output; }
In development environment every developer need to debug the bugs. If a boolen value provided in config when we need we can disable it . I suggest this as improvement
Hello
Is that possible to include a parameter to add a ?version= for a CSS/JS minified file if build is set to TRUE (or if build has been made because of a change in the files) ?
I got a cache system for JS/CSS files and I need to clear cache to update and get last version of file
With ?version= I won't need anymore to clear cache as it will add a new version each time it builds
Regards
Hi,
How to generate minified folder in the same folder as the css and js files ?
If my css file is in assets/css and js in assets/js I would like minified versions created in the same folder.
In the config file, it is only possible to set an unique asset folder for generated files. So we can't specify different folders for css and js.
Relative URL to images in css files will be broken if minified file is not generated in the same folder!
Hello,
could you please specify a license for CI-minify?
Otherwise I won't be able to use it.
Thanks,
Domenico
I did as told in the read me, it's not deploying. I checked the file permission, but in vain.
Hello
how i can set my another files Directories
for example:
Assets/css/bootstrap/bootstrap.min.css
Assets/css/font-awesome/font-awesome.min.css
thank you
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.