On Sep 13, 11:33 am, valotas <valo...@gmail.com> wrote:
> I also think that javascript should go just before the boby's closing
> tag. The main reason: Yahoo's YSlow and Google's Page speed both
> telling you that is better to have as less scripts as possible and all
> of them placed at the end of the page. The optimal would be one
> javascript at the end of the page no matter how big it is as it would
> be cached by any modern browser and it will be used from the local
> cache on other requests from the same domain.
>
> Of course optimal is not always what you can get. Assuming that you
> have many javascript files it is also better to have them at the
> bottom of the page. You will see a major performance boost because
> browsers pause the rendering of the page in order to download
> javascript. That is because javascript code could contain a
> document.write witch means that it will change the dom of the page and
> this is something that the browser will not be able to know in advance
> in order to continue the parsing of the page. Moving javascript at the
> bottom of the page will not decrease the page loading time BUT will
> give the user something to see (the whole page) making him thing that
> the page loads faster. Of course the browser will still have to get
> the javascript and eval it.
>
> As for unobtrusive, jquery (and the most js frameworks) provides a
> solution binding an event on an html element after the page has been
> loaded. So instead of having somthing like:
> <button onclick="liftAjax.lift_ajaxHandler
> (&quot;F1029758482780OTA=true&quot;,
> null, null, null); return false;">Press me</button>
>
> you could have something like:
> <button id="liftajax_{some_generated_id}">Press me</button>
>
> and at the end of the page add the javascript:
> <text type="text/javascript">
> $(function() {
> $("#liftajax_{some_generated_id}").click(function()
> {the_lift_ajaxHandler_call_here()})})
>
> </script>

That looks a little cleaner but we'll have to look more into it if
we'd want to go on this path. Perhaps accumulate those function into
synthetic js file .. we'll see

>
> If the ajax handle call is basically the same for most of the elements
> you could instead of adding an id, add a class to the the button for
> example:
> <button class="liftajax">Press me</button>
>
> and then at the end of the page add:
> <text type="text/javascript">
> $(function() {
> $(".liftajax").click(function() {the_lift_ajaxHandler_call_here()})})

Two reason why I don't prefer this:

1. Lots of selectors could slow things down
2. Other JS frameworks may not have nice selectors as JQuery

>
> </script>
>
> I personally use jQuery but the above can be done without the help of
> any javascript framework. And to make things much more better you
> could have all the handler scripts in a separete dynamicaly created
> file and the at the end of the html have something like:
> <script type="text/javscript" src="/path/to/the/dynamicaly/created/js/
> with/a/random/id/to/prevent/caching"></script>
>
> One reason for keeping me away from using lift for a project is this
> "mess" with javascript. I mean, I first want plain html and nothing
> else. If I get the html to work for me the I just add the javascript I
> want or let the framework add it, but that should be done in an
> elegant way in order to be able to switch it off or on or completely
> replace it with my own. I don't want any framework to add by default
> the javascript for me because it makes things harder to understand and
> this is something bad for someone new to it.
>
> I would be glad to help in this matter in any way possible.
>
> Sorry for my English,
> it's not my mother language!

I think this is a great post !

>
> Yoryos
>
> On Sep 13, 6:35 am, "marius d." <marius.dan...@gmail.com> wrote:
>
> > Technically it could (as I implied above) but this can be lucrative
> > and IMHO the benefits are simply not that big. I'm not saying that
> > things are nailed down but I'd love to see a list of practical
> > benefits for Lift to not add event handlers such as on click to the
> > elements but rather programatically using synthetic (lift generated)
> > JS functions that would add events (i.e. JQuery, YUI ways).
>
> > Br's,
> > Marius
>
> > On Sep 12, 9:05 pm, Naftoli Gugenheim <naftoli...@gmail.com> wrote:
>
> > > Maybe adding javascript event handlers could be delegated to something 
> > > that depends on which library is being used?
>
> > > -------------------------------------
>
> > > Kevin Wright<kev.lee.wri...@googlemail.com> wrote:
>
> > > Moving the script import shouldn't be too difficult, we have the 
> > > <lift:tail>
> > > element and tail merge (which acts exactly the same as head merge) for 
> > > just
> > > this sort of problem.
>
> > > On Sat, Sep 12, 2009 at 8:07 PM, Dustin Whitney 
> > > <dustin.whit...@gmail.com>wrote:
>
> > > > One nice thing about jquery's events, if done wisely, is they are 
> > > > applied
> > > > after the DOM is loaded.  With an onclick a button can be clicked and 
> > > > some
> > > > ajax call is fired that returns and tries to modify a part of the DOM 
> > > > that
> > > > hasn't been loaded.  This is especially true if you have lots of 
> > > > javascript
> > > > includes at the top of the page.  I have waded my way through many wonky
> > > > javascript bugs like this.  They don't happen in your local environment
> > > > because they load so quickly, but when pushed to production, problems
> > > > ensue.  Maybe there is a hook in the lift ajax js that waits to fire the
> > > > call until after the DOM is loaded?
>
> > > > -D
>
> > > > On Sat, Sep 12, 2009 at 2:48 PM, Charles F. Munat <c...@munat.com> 
> > > > wrote:
>
> > > >> I, too, would like to be able to move the liftAjax script call to the
> > > >> bottom of the page.
>
> > > >> Chas.
>
> > > >> Dustin Whitney wrote:
> > > >> > Hey, I like Lift so in an effort to improve it I am submitting some
> > > >> > criticism.
>
> > > >> > Obtrusive javascript:
>
> > > >> > when I create an ajaxButton I get this html:
>
> > > >> > <button
> > > >> onclick="liftAjax.lift_ajaxHandler(&quot;F1029758482780OTA=true&quot;, 
> > > >> null,
> > > >> null, null); return false;">Press me</button>
>
> > > >> > That onclick is not ok.  It's bad for SEO and makes the page harder 
> > > >> > to
> > > >> > read.  Ideally, no javascript should appear on the page whatsoever.
>
> > > >> > Client Side Load Time:
>
> > > >> > I strive for that A in Y-Slow, so when I see
>
> > > >> > <script type="text/javascript" src="/ajax_request/liftAjax.js
> > > >> <view-source:http://localhost:8080/ajax_request/liftAjax.js>"></script>
>
> > > >> > at the top of the page, I feel a little uneasy, and there is nothing 
> > > >> > I
> > > >> > can do (I think) to move it to the bottom of the page.
>
> > > >> > -Dustin
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Lift" group.
To post to this group, send email to liftweb@googlegroups.com
To unsubscribe from this group, send email to 
liftweb+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/liftweb?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to