Goo::CompressWhitespace - Remove excess whitespace


Goo documentation Contained in the Goo distribution.

Index


Code Index:

NAME

Top

Goo::CompressWhitespace - Remove excess whitespace

SYNOPSIS

Top

use Goo::CompressWhitespace;

DESCRIPTION

Top

METHODS

Top

compress_html

remove excess whitespace in HTML and Javascript to reduce overall byte size

AUTHOR

Top

Nigel Hamilton <nigel@trexy.com>

SEE ALSO

Top


Goo documentation Contained in the Goo distribution.

package Goo::CompressWhitespace;

###############################################################################
# Nigel Hamilton
#
# Copyright Nigel Hamilton 2005
# All Rights Reserved
#
# Author: 		Nigel Hamilton
# Filename: 	Goo::CompressWhitespace.pm
# Description: 	Remove whitespace for web transmission
#
# Date 			Change
# -----------------------------------------------------------------------------
# 02/02/2005 	Auto generated file
# 02/02/2005 	Needed to reduce filesizes for more speed!
#				Ideally all pages should be less than 1300 MTU (allowing for 
#				HTTP headers).
#
###############################################################################

use strict;


###############################################################################
#
# compress_html - remove excess white space in html
#
###############################################################################

sub compress_html {
	
	my ($string_ref) = @_;

	# strip whitespace but preserve newlines
	# to avoid Javascript bugs
	$$string_ref =~ s{([\s\n]+)}{($1 =~ /\n/) ? "\n" : " "}eg;

	# remove spaces around = signs
	$$string_ref =~ s/\s+\=\s+/=/g;
					
	# strip single spaces between tags
	$$string_ref =~ s/\>\s\</\>\</g;
	
	#return $string_ref;

}

1;


__END__