Monday, 15 July 2013

How to Remove unnecessary white spaces from xhtml/xml/html content - Mod_Trim

Want to remove unnecessary white spaces from xhtml/xml/html content? Which Makes your page size reduced by 25-30 % and enhance your application performance.


Detail:


Mod_Trim is an apache module which removeunnecessary white spaces from xhtml/xml/html content

Steps to implement this:

1) Go to website http://www.thrull.com/corner/webserver/mod-trim/ and download mod_trim module.

2) Run below commands. Remember to have sudo access on your server

sudo yum install httpd-devel [For apxs]
which apxs
./configure --with-apxs=/usr/sbin/apxs
cd src
make -f Makefile.apxs

[kulshresht@server123 .libs]$ pwd
/tmp/mod_trim-1.0/src/.libs
[kulshresht@server123 .libs]$ sudo cp -r mod_trim.so /etc/httpd/modules


2) Uncommnet this in httpd.conf file of Apache.
LoadModule filter_module modules/mod_filter.so


3)  Create a file trim.conf in conf.d folder of Apache and put below lines in that file :
# enable module (this line should sometimes be added in modules.conf if you have one)
LoadModule trim_module modules/mod_trim.so

# add filtering
FilterProvider trim-filter TRIM resp=Content-Type $text/html
FilterChain trim-filter

4) Restart Apache and you are done. 


Explained better at this link: http://www.thrull.com/corner/webserver/mod-trim/


Note :

One most important point to remember in the course of making these changes is:

Do not use one line JavaScript (e.g. // … double slash) instead of that use block comment (e.g /*.......*/)

Usage of single line comment might treat your entire code block as comment because mod_trim will trim new lines and or spaces. See below code snippet for explanation:

Before mod_trim action

// Add a script element as a child of the loadAnalyticsScript
<!--  GOOGLE ANALYSTICS SCRIPT STARTS -->
          var _gaq = _gaq || [];
          _gaq.push(['_setAccount', 'UA-2260765-1']);
...


After mod_trim action

// Add a script element as a child of the loadAnalyticsScript <!--  GOOGLE ANALYSTICS SCRIPT STARTS --> var _gaq = _gaq || []; _gaq.push(['_setAccount', 'UA-2260765-1']);




No comments:

Post a Comment