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

Compress! Compress!! Compress!!!

 
Post new topic   Reply to topic    Smarty Forum Index -> Tips and Tricks
View previous topic :: View next topic  
Author Message
bimal
Smarty Elite


Joined: 19 Apr 2007
Posts: 423

PostPosted: Fri Mar 20, 2009 4:26 pm    Post subject: Compress! Compress!! Compress!!! Reply with quote

Visit first: http://developer.yahoo.com/performance/rules.html

Please read the above URL, because that is great, over my few comments below:

$marty's {strip} ... {/strip} plugin has a very nice compression feature. Since Unnecessary white-spaces (Tabs, New lines and Spaces) in the HTML output is really useless, remove them.

Even if code formatting is recommended, that has no use other than letting people steal your data easily. Many Search engines should have used Regular Expressions and whatever tight codes you write (ideally, that without white spaces), it still should become SEO friendly.

Search engines don't just limit to your code formatting to index information in your web pages!

So, with Smarty, you can write clean templates but compressed HTML output. Enjoy serving lesser HTML. Do not just send white spaces spams to the browsers!

How is the idea?


Last edited by bimal on Fri Apr 03, 2009 4:25 am; edited 1 time in total
Back to top
View user's profile Send private message Visit poster's website
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7361
Location: Lincoln Nebraska, USA

PostPosted: Fri Mar 20, 2009 4:51 pm    Post subject: Reply with quote

You can shorten up all of your html with the trimwhitespace output filter.
Back to top
View user's profile Send private message Visit poster's website
rustybucket
Smarty Regular


Joined: 28 Jan 2009
Posts: 60

PostPosted: Thu Apr 02, 2009 7:43 pm    Post subject: Reply with quote

You are the MAN Bimal! I've been through the docs now a couple of times and never noticed this!

Thanks!
Back to top
View user's profile Send private message
bimal
Smarty Elite


Joined: 19 Apr 2007
Posts: 423

PostPosted: Fri Apr 03, 2009 4:26 am    Post subject: Thanks! Reply with quote

Thanks.

But I noticed that the correct link to Yahoo page is:
http://developer.yahoo.com/performance/rules.html
And, I edited my post.
Back to top
View user's profile Send private message Visit poster's website
chishikinohito
Smarty Regular


Joined: 29 Nov 2010
Posts: 54

PostPosted: Tue Dec 09, 2014 12:32 pm    Post subject: Thanks, this is nice Reply with quote

It's really cool to out put everything as single line rather than structured content.

Is anybody aware if it's possible to refrain from doing it in every template though?

I would rather put it once on the very top, in `header.tpl` and in the very bottom, in `footer.tpl`.

It seems that Smarty tags are not transferred through the templates?

Is there a safe work around?
Back to top
View user's profile Send private message
prophet
Smarty n00b


Joined: 09 Dec 2014
Posts: 3

PostPosted: Tue Dec 09, 2014 1:53 pm    Post subject: Re: Thanks, this is nice Reply with quote

chishikinohito wrote:
It's really cool to out put everything as single line rather than structured content.

Is anybody aware if it's possible to refrain from doing it in every template though?

I would rather put it once on the very top, in `header.tpl` and in the very bottom, in `footer.tpl`.

It seems that Smarty tags are not transferred through the templates?

Is there a safe work around?


+1 to this question. It's quite annoying to have to remember to put {strip} tags inside each small template. Would rather enable it globally, or, at least, in the header and footer tags to do it everywhere in between.
Back to top
View user's profile Send private message
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7361
Location: Lincoln Nebraska, USA

PostPosted: Tue Dec 09, 2014 3:34 pm    Post subject: Reply with quote

You could create an output filter that modifies the output text. This would apply to all templates inclusive to a display() or fetch() call.
Back to top
View user's profile Send private message Visit poster's website
chishikinohito
Smarty Regular


Joined: 29 Nov 2010
Posts: 54

PostPosted: Tue Dec 09, 2014 6:36 pm    Post subject: Reply with quote

How do you use it with display or fetch, could you give it an example please?
Back to top
View user's profile Send private message
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1127

PostPosted: Tue Dec 09, 2014 11:38 pm    Post subject: Reply with quote

Just create and register an output filter.
Then it will be applied automatically, when you call Smarty::display or Smarty::fetch
Back to top
View user's profile Send private message
U.Tews
Administrator


Joined: 22 Nov 2006
Posts: 5059
Location: Hamburg / Germany

PostPosted: Wed Dec 10, 2014 12:43 am    Post subject: Reply with quote

You may try
Code:
$smarty->loadFilter('output', 'trimwhitespace');

which does exists in the plugins folder.
Back to top
View user's profile Send private message
chishikinohito
Smarty Regular


Joined: 29 Nov 2010
Posts: 54

PostPosted: Wed Dec 10, 2014 7:03 am    Post subject: Reply with quote

Thank you, that is really fast-forward solution!
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Smarty Forum Index -> Tips and Tricks 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