View previous topic :: View next topic |
Useful ? |
Yes |
|
57% |
[ 4 ] |
No |
|
42% |
[ 3 ] |
|
Total Votes : 7 |
|
Author |
Message |
KakkArlak Smarty Rookie
Joined: 25 Nov 2009 Posts: 8
|
Posted: Mon Dec 13, 2010 7:13 am Post subject: HTML minifying |
|
|
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 |
|
elpmis Smarty Elite
Joined: 07 Jun 2007 Posts: 321
|
|
Back to top |
|
KakkArlak Smarty Rookie
Joined: 25 Nov 2009 Posts: 8
|
Posted: Mon Dec 13, 2010 12:09 pm Post subject: |
|
|
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 |
|
elpmis Smarty Elite
Joined: 07 Jun 2007 Posts: 321
|
Posted: Mon Dec 13, 2010 1:27 pm Post subject: |
|
|
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 |
|
KakkArlak Smarty Rookie
Joined: 25 Nov 2009 Posts: 8
|
Posted: Mon Dec 13, 2010 2:05 pm Post subject: |
|
|
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 |
|
elpmis Smarty Elite
Joined: 07 Jun 2007 Posts: 321
|
Posted: Mon Dec 13, 2010 2:10 pm Post subject: |
|
|
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 |
|
mackenzie02 Smarty n00b
Joined: 16 Feb 2011 Posts: 2 Location: Zurich
|
Posted: Fri Feb 25, 2011 9:33 pm Post subject: That's a good tip |
|
|
Good tip, wasn't aware of {strip} either. Thanks |
|
Back to top |
|
olivierpons Smarty Rookie
Joined: 13 Aug 2011 Posts: 13 Location: France
|
Posted: Sat Aug 13, 2011 11:10 am Post subject: |
|
|
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" |
|
Back to top |
|
traxion Smarty n00b
Joined: 24 Jul 2009 Posts: 1
|
Posted: Tue Aug 30, 2011 6:23 pm Post subject: |
|
|
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
cleared my changes, then some less optimised code, but valid |
|
Back to top |
|
t3hAndy Smarty Rookie
Joined: 10 Sep 2008 Posts: 12
|
Posted: Thu Sep 15, 2011 7:00 am Post subject: |
|
|
It would be very nice if i could set a flag and strip is used automatically
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 |
|
rodneyrehm Administrator
Joined: 30 Mar 2007 Posts: 674 Location: Germany, border to Switzerland
|
Posted: Thu Sep 15, 2011 7:31 am Post subject: |
|
|
t3hAndy wrote: | It would be very nice if i could set a flag and strip is used automatically
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 |
|
t3hAndy Smarty Rookie
Joined: 10 Sep 2008 Posts: 12
|
Posted: Fri Oct 14, 2011 7:17 am Post subject: |
|
|
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 |
|
rodneyrehm Administrator
Joined: 30 Mar 2007 Posts: 674 Location: Germany, border to Switzerland
|
Posted: Fri Oct 14, 2011 8:56 am Post subject: |
|
|
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 |
|
t3hAndy Smarty Rookie
Joined: 10 Sep 2008 Posts: 12
|
Posted: Tue Nov 01, 2011 5:13 pm Post subject: |
|
|
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 |
|
mazzucato Smarty n00b
Joined: 14 Apr 2017 Posts: 1
|
Posted: Fri Apr 14, 2017 3:44 am Post subject: Smarty Combine |
|
|
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 |
|
|