• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Minify CSS and JS in CodeIgniter

#11
also use mod_pagespeed (if you can) for minify content.

Reply

#12
I'm pretty sure CI 3.0 has a minifier....
Reply

#13
Narf there is minify in CI 3.0 but its only about inline minify (content X type).

I believe that it is a huge plus if developers are able to organize their static files (css,js,fonts and perhaps img's) using one common Minify/Assets library (best will be to have 1 lib for both things).
You know that lets say google page speed opt. always advice to have less numbers of JS , CSS files and etc.
If developer have the option to specify the required JS, CSS and to minify them automatic this can be a huge bonus.

Just sample what I mean:
1st > Let say that I need 3 js files in all pages so by configuration - I can specify them into assets/minify config file like the autoload file.
2nd > In some page I may need 3 more JS files (some ui) - I add them to this library Assets/Minify.
Final> At the end at the page template I will just put something as <?=$output->outputJS()?> which will generate codes from type
Code:
<script src="BASE URL / assets / js / file.js"></script>
. This file will contain all JS files added to this class.

Of course there are multiple cases to think for ..
Lets say JS in head , or don't minify JS, don't merge JS (with other files), DEBUG mode without minify and etc... same with CSS ..
Best VPS Hosting : Digital Ocean
Reply

#14
(11-11-2014, 05:59 AM)sv3tli0 Wrote: Narf there is minify in CI 3.0 but its only about inline minify (content X type).

I believe that it is a huge plus if developers are able to organize their static files (css,js,fonts and perhaps img's) using one common Minify/Assets library (best will be to have 1 lib for both things).
You know that lets say google page speed opt. always advice to have less numbers of JS , CSS files and etc.
If developer have the option to specify the required JS, CSS and to minify them automatic this can be a huge bonus.

Just sample what I mean:
1st > Let say that I need 3 js files in all pages so by configuration - I can specify them into assets/minify config file like the autoload file.
2nd > In some page I may need 3 more JS files (some ui) - I add them to this library Assets/Minify.
Final> At the end at the page template I will just put something as <?=$output->outputJS()?> which will generate codes from type
Code:
<script src="BASE URL / assets / js / file.js"></script>
. This file will contain all JS files added to this class.

Of course there are multiple cases to think for ..
Lets say JS in head , or don't minify JS, don't merge JS (with other files), DEBUG mode without minify and etc... same with CSS ..

I do something similar to this in one of my projects.

It is much more simple than what you are proposing, but I think the idea is the same.

In my project, when any page is printed out, there is a QR code printed on the page, which has the URL of the page embedded within. The QR code is only ever generated once for a URL, so the image is then only ever served. This gives neat function and zero server overhead.

Something similar could be done here, have a set of methods on the Minify Class, which add assets to the page. An ID is generated, perhaps from the URL or page URL without any parameters (as it should always be the same).

If the bundle exists, return it to the caller, if not, generate the minified asset bundle, JS or CSS or anything else, say a new format type.

It would be possible to easily revalidate the minified bundle either with a command in the controller, or a timestamp in the generated view.

We could then have page by page minification. It would waste a little space, but would be fairly simple and reliable.

It could be extended to use a key and shared between pages, which is common in the way things are done now, but a little to much hassle to do all at once.

What do you think?
Reply

#15
Found this project on github ... maybe its usefull for you.

https://github.com/avenirer/Assetor

Just saw a post for this lib here .. so any discussion about it should be goto

http://forum.codeigniter.com/thread-54.html

Reply

#16
Minimee is pretty great for ExpressionEngine -- http://johndwells.github.io/Minimee/

Perhaps someone would like to fork and rework for CI?
Reply

#17
I've used Minify in several of my projects, about the only concern is a developer forgetting to add a semi-colon in JS or breaking a CSS rule and having the minify/merged result produce errors. This can be mitigated by using compilation in your testing environment, while leaving development to using raw source files so it doesn't slow you down.

The biggest issue with building this into CI is the fact it doesn't really force you into a project structure. Personally I think CI should embrace HMVC and enforce it going forward, but until they do trying to support many folder layouts would get messy, fast.
Reply

#18
Can anyone share or make an example of minify js and css with grunt in codeigniter 3? Please.
Reply

#19
(11-11-2014, 05:59 AM)sv3tli0 Wrote: Narf there is minify in CI 3.0 but its only about inline minify (content X type).

I believe that it is a huge plus if developers are able to organize their static files (css,js,fonts and perhaps img's) using one common Minify/Assets library (best will be to have 1 lib for both things).
You know that lets say google page speed opt. always advice to have less numbers of JS , CSS files and etc.
If developer have the option to specify the required JS, CSS and to minify css them automatic this can be a huge bonus.

Just sample what I mean:
1st  >  Let say that I need 3 js files in all pages so by configuration - I can specify them into assets/minify config file like the autoload file.
2nd >  In some page I may need 3 more JS files (some ui) - I add them to this library Assets/Minify.
Final>  At the end at the page template I will just put something as <?=$output->outputJS()?> which will generate codes from type
Code:
<script src="BASE URL / assets / js / file.js"></script>
. This file will contain all JS files added to this class.

Of course there are multiple cases to think for ..
Lets say JS in head , or don't minify JS, don't merge JS (with other files), DEBUG mode without minify and etc... same with CSS ..

thanks, it's useful, saves me a lot of time.
Reply

#20
+1 for Grunt and Sass. I set up Grunt to output more than one version of my CSS, which is helpful for having a minified and non-minified version available.
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.