Smarty Forum Index Smarty
The discussions here are for Smarty, a template engine for the PHP programming language.
HTML minifying

 
Post new topic   Reply to topic    Smarty Forum Index -> Feature Requests
View previous topic :: View next topic  

Useful ?
Yes
60%
 60%  [ 3 ]
No
40%
 40%  [ 2 ]
Total Votes : 5

Author Message
KakkArlak
Smarty Rookie


Joined: 25 Nov 2009
Posts: 8

PostPosted: Mon Dec 13, 2010 7:13 am    Post subject: HTML minifying Reply with quote

Wouldn't it be nice to have HTML minifying included in Smarty ?

E.g., Some property :
$smarty->minifyHtml = true;

and then the display/fetch minify's the output html if the above property is true. (defaults to false ofcourse)

Yes/no ?
Back to top
View user's profile Send private message
elpmis
Smarty Elite


Joined: 07 Jun 2007
Posts: 259

PostPosted: Mon Dec 13, 2010 10:24 am    Post subject: Reply with quote

Have you checked the strip tag?

http://www.smarty.net/docs/en/language.function.strip.tpl
Back to top
View user's profile Send private message
KakkArlak
Smarty Rookie


Joined: 25 Nov 2009
Posts: 8

PostPosted: Mon Dec 13, 2010 12:09 pm    Post subject: Reply with quote

Oh, right, I actually didn't know about that one..

Only problem with that is, I'd have to manually put those in? And I if I for some reason want to turn it off, I'd have to manually do so, instead of changing a true to a false?
Back to top
View user's profile Send private message
elpmis
Smarty Elite


Joined: 07 Jun 2007
Posts: 259

PostPosted: Mon Dec 13, 2010 1:27 pm    Post subject: Reply with quote

Put this in your template file

Code:
{strip}
... your template ...
{/strip}


If you dont want this you can deactivate strip

Code:
{* strip *}
... your template ...
{/strip}
Back to top
View user's profile Send private message
KakkArlak
Smarty Rookie


Joined: 25 Nov 2009
Posts: 8

PostPosted: Mon Dec 13, 2010 2:05 pm    Post subject: Reply with quote

elpmis wrote:
Put this in your template file

Code:
{strip}
... your template ...
{/strip}


If you dont want this you can deactivate strip

Code:
{* strip *}
... your template ...
{/strip}
Yes, that's fine, but my point is that I would then have to go and comment that out in each template.
Back to top
View user's profile Send private message
elpmis
Smarty Elite


Joined: 07 Jun 2007
Posts: 259

PostPosted: Mon Dec 13, 2010 2:10 pm    Post subject: Reply with quote

Dont know which system you are using ... maybe you have a chance to pass a status variable to your template. Meaned status for showing html minified or not.

If yes you can use it like

Code:
{if $status == true}
{strip}
{/if}
... your template ...
{/strip}
Back to top
View user's profile Send private message
mackenzie02
Smarty n00b


Joined: 16 Feb 2011
Posts: 2
Location: Zurich

PostPosted: Fri Feb 25, 2011 9:33 pm    Post subject: That's a good tip Reply with quote

Good tip, wasn't aware of {strip} either. Thanks
Back to top
View user's profile Send private message Visit poster's website
olivierpons
Smarty Rookie


Joined: 13 Aug 2011
Posts: 13
Location: France

PostPosted: Sat Aug 13, 2011 11:10 am    Post subject: Reply with quote

Note: if you have JavaScript in your html file, using {literal} {/literal} won't touch the code between those tags, and your JavaScript won't be "stripped" Wink
Back to top
View user's profile Send private message Visit poster's website
traxion
Smarty n00b


Joined: 24 Jul 2009
Posts: 1

PostPosted: Tue Aug 30, 2011 6:23 pm    Post subject: Reply with quote

anyway to change the smarty framework so it will be done automatic?

uhm.. after some testing i've noticed that the {strip} feature is not w3 valid. It got mine pages from valid on w3 validator to unvalid Sad

cleared my changes, then some less optimised code, but valid
Back to top
View user's profile Send private message
t3hAndy
Smarty Rookie


Joined: 10 Sep 2008
Posts: 12

PostPosted: Thu Sep 15, 2011 7:00 am    Post subject: Reply with quote

It would be very nice if i could set a flag and strip is used automatically Wink
So, I could minify the traffic at my live system, but don't use strip on the development environment
_________________
I developed a Webradio
Back to top
View user's profile Send private message
rodneyrehm
Administrator


Joined: 30 Mar 2007
Posts: 698
Location: Germany, border to Switzerland

PostPosted: Thu Sep 15, 2011 7:31 am    Post subject: Reply with quote

t3hAndy wrote:
It would be very nice if i could set a flag and strip is used automatically Wink
So, I could minify the traffic at my live system, but don't use strip on the development environment


Have a look at the outputfilter.trimwhitespace.php plugin
_________________
Twitter
Back to top
View user's profile Send private message Visit poster's website
t3hAndy
Smarty Rookie


Joined: 10 Sep 2008
Posts: 12

PostPosted: Fri Oct 14, 2011 7:17 am    Post subject: Reply with quote

hey globe,

look's very good. thanks. I'm running smarty with that filter now.
But, I think there is a small "problem".

The filter is a outputfilter. I think it would be better to use the filter while creating the "compiled" file. So the server don't have to run the filter on each call.

How can I handle that? Is there a posibility?

thanks a lot
_________________
I developed a Webradio
Back to top
View user's profile Send private message
rodneyrehm
Administrator


Joined: 30 Mar 2007
Posts: 698
Location: Germany, border to Switzerland

PostPosted: Fri Oct 14, 2011 8:56 am    Post subject: Reply with quote

Well, having this run as outputfilter also makes sure that

Code:
<p>{$someUserCommentOrSomeSuch}</p>
wont end up in
Code:
<p>
                    Hello people,
   nice     thing you've got going here




</p>


That wouldn't work if you were running the minifcation at compile time.
_________________
Twitter
Back to top
View user's profile Send private message Visit poster's website
jacz
Smarty Pro


Joined: 13 Nov 2010
Posts: 249

PostPosted: Fri Oct 14, 2011 11:55 am    Post subject: Reply with quote

Minify HTML is something of Google Pagespeed.

You can loose more time and real speed as you can win if you want best results .

Problems are inline Javascript, Inline CSS and sometimes inline Images as base64, but these are things that makes the best speed, and not minify html.

Strip or trimwhitespace is a small solution and you can get sometimes results that makes a site not working.

I use an own minify method with no best results but it works in all cases and it was not general for all systems it is for my system and i have a pagespeed 100/100 Web.
Back to top
View user's profile Send private message Visit poster's website
t3hAndy
Smarty Rookie


Joined: 10 Sep 2008
Posts: 12

PostPosted: Tue Nov 01, 2011 5:13 pm    Post subject: Reply with quote

rodneyrehm wrote:
Code:
<p>
                    Hello people,
   nice     thing you've got going here




</p>

That wouldn't work if you were running the minifcation at compile time.


But, the browser will not to display the formatted text in <p> tag
It's displayed like:
Code:
Hello people, nice thing you've got going here

_________________
I developed a Webradio
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Smarty Forum Index -> Feature Requests All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP