Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

HTML minifying
Goto page 1, 2  Next
 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Feature Requests
View previous topic :: View next topic  

Useful ?
Yes
57%
 57%  [ 4 ]
No
42%
 42%  [ 3 ]
Total Votes : 7

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: 321

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: 321

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: 321

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: 674
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: 674
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
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
mazzucato
Smarty n00b


Joined: 14 Apr 2017
Posts: 1

PostPosted: Fri Apr 14, 2017 3:44 am    Post subject: Smarty Combine Reply with quote

There is an awesome plugin called Smarty Combine, it combines and minify multiple JS and CSS, you can take a look at:

https://github.com/dead23angel/smarty-combine

Example (Smarty 3):

{combine input=array('/file1.js','/file2.js') output='/cache/big.js' age='30' debug=false}
Back to top
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Feature Requests All times are GMT
Goto page 1, 2  Next
Page 1 of 2

 
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