![]() |
how to compress the html/js/style files in codeigniter ??? - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: how to compress the html/js/style files in codeigniter ??? (/showthread.php?tid=22367) |
how to compress the html/js/style files in codeigniter ??? - El Forum - 09-07-2009 [eluser]mythilisubramanyam[/eluser] can i use gzip or defalte to compress html/js/style/image files???? or is there any other option to compress them ??? how to compress the html/js/style files in codeigniter ??? - El Forum - 09-07-2009 [eluser]bretticus[/eluser] Yes, but even though this can be done with PHP it is much more efficient to let your webserver do this. mod deflate in apache can perform this for you. If this is a shared hosting server, well, unless your hosting supports this (they may already) I wouldn't worry about it. image files are usually compressed as much as they will compress and plain text files should be relatively small for a well-designed website. I'm not saying that compression isn't a good thing. I'm just saying that if you have to do it with code, it's too much expense for a little gain. how to compress the html/js/style files in codeigniter ??? - El Forum - 09-07-2009 [eluser]Johan André[/eluser] Well, js, css and image are usually static so combine and squeeze (using minify and cssmin) them and cache the result. Serve the (minified) file from cache. With javascript and css there tends to be alot of http-requests if you have alot of files. Combining all js to one http-request usually gives a more responsive site... how to compress the html/js/style files in codeigniter ??? - El Forum - 09-07-2009 [eluser]John_Betong[/eluser] With regards to compression I tried changing this setting ./config/config.php Code: config['compress_output'] = TRUE; // FALSE; // default I investigated further in the forum and came across this code that I adapted for my own benefit. On average it reduces the $result by about 10%. Code: if (LOCALHOST) // DO NOT compress result I am curious to know what happens to the css/js files that are referenced in the $result. Are they expanded then compressed or does the reference get passed through to the browser where it is finally loaded? how to compress the html/js/style files in codeigniter ??? - El Forum - 09-07-2009 [eluser]Nick Husher[/eluser] [quote author="mythilisubramanyam" date="1252323375"]can i use gzip or defalte to compress html/js/style/image files???? or is there any other option to compress them ???[/quote] You can definitely use gzip to compress files. That's a server configuration, though, and has nothing to do with CodeIgniter. Check out the relevant web server documentation on turning on a gzip filter. There are a heap of tools for minifying javascript and css. I've heard the best javascript minifier out there is the one put out Yahoo, but it requires a certain amount of java handwaving. Still, if bit weight is your primary concern, writing a simple compressor shell script to run the YUI compressor on all your script/css files might be worthwhile. For images, you can use smushit, which doesn't further compress your lossy-compressed images (jpeg, gif, etc), but it rips out certain bits of metadata as well as optimizes in some ways that major image programs (Photoshop, I'm lookin' at you) miss when you export them into web-friendly formats. how to compress the html/js/style files in codeigniter ??? - El Forum - 07-22-2010 [eluser]Spir[/eluser] On my projects I usually make a sub domain for static content : js, css and images. I have something like this : /system /application /static → static content goes here (http://static.example.com) /www → index.php goes here (http://example.com) So I have 2 htaccess one for static content, another for www (my CI app) Here is an example of what I usually put in htacces for static content (could be better): Code: # Add deflate to static content http://code.google.com/p/minify It permits to minify my CSS and JS on the fly and cache the result so it will be quicker next time. Example : you have 4 js files : jquery-1.3.2.min.js jquery-ui-1.7.2.min.js jquery-ui-1.7.2.datepicker.min.js my_script.js You may have put all files in one JS file : great. But fomr some maintenance and reusage you may keep them in one file. This will result in calling 4 files like this : Code: type="text/javascript" src="http://static.example.com/js/jquery-1.3.2.min.js" Using that code (http://code.google.com/p/minify) you could dynamically minify them in one file like this : Code: type="text/javascript" src="http://static.example.com/min/?f=js/jquery-1.3.2.min.js,js/jquery-ui-1.7.2.min.js,js/jquery-ui-1.7.2.datepicker.min.js,js/my_script.js" Same goes for CSS. Here is what I have for my www/ folder : Code: <IfModule mod_rewrite.c> But you see my content delivered by my app do not use deflate. Before printing my <html> tag I put this : ob_start("ob_gzhandler"); and then right after my </head> tag I put this : ob_flush(); flush(); You can learn more about this there : http://www.phpied.com/progressive-rendering-via-multiple-flushes/ Now this is not all, I should also minify my html code. Here are some tips : http://maestric.com/doc/php/codeigniter_compress_html This few tasks will make your website quicker. |