RE: Intelligent JavaScript handling

"Scott Matthewman" <[email protected]>
Newsgroups gmane.comp.php.smarty.devel
Message-ID <008401c40c4d$4c897b30$0200a8c0@APOLLO>
> -----Original Message-----
> From: Monte Ohrt [mailto:[email protected]] 
> Sent: 17 March 2004 16:33
> 
> Another option is replacing "{" with "{ldelim}" and "}" with 
> "{rdelim}",
> since that wasn't mentioned. There usually aren't too many of 
> them, one
> pair per javascript function or css definition.

At the risk of veering off-topic, this particular thread is poitning out to
me (as a developer who uses Smarty)) that people are programming JavaScript
inefficiently.

If you're using Smarty to write out fresh JavaScript all the time, with
variable values droppen in where necessary, you would be better off using
functions in your JavaScript function definitions, so that the only lines
that need to have Smarty insert variables are the function *calls*.

If you can get into this habit, then your resultant HTML+Javascript will (a)
generally end up being smaller in size, if two of more blocks of JS code can
be replaced with two calls to one parameterised function; and (b) load
quicker, if you are then able to store your Javascript functions in a
separate file (i.e., with <script src="..."></script>) which browsers can
then cache independently of however many HTML pages need to use the same
function.

It'll also make debugging code easier, as you know that the JS code won't be
changing every time you generate a new page from your templates... ;)

Just my twopenn'orth, as my grandmother used to say,

Scott

-- 
Smarty Development Mailing List (http://smarty.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.