But I hear 'ya! I have an admin page with 100 rows of drap-and-drop + in-place editing -- not only is it a lot of HTML, Safari runs like its legs are cut off at the knees.
solved the onload woe it’s easy to make suckerfish-like solutions. For your delete example, you could do something like this:
- Create a single function that accepts dom element, parses the text appropriately and makes the ajax call (using prototype if you wish)
- Create a separate function that loops through all of the links on the page that have a certain class (which prototype makes easy) and add an onclick event handler that passes the link to the function
You should be aware (and someone please correct me if I’m wrong) that using UJS can significantly slow down performance for pages with large numbers of elements.
On most pages, it won’t be a problem. But in our case, we had a page with many, many elements, and the slow down and CPU usage was painful.
Again, I could be wrong, but something to consider.
Steve Bergman wrote:
BTW, anyone know why the image src is set to /images/delete.png?1156712862 instead of just /images/delete.png?
You shouldn't see that in production, so it should be fine!
To further reduce the file size, you could insert the image tag dynamically as well. Which will reduce your html to :
BTW, anyone know why the image src is set to
/images/delete.png?1156712862 instead of just /images/delete.png?
I agree that using UJS and a lot of css selectors could lead to poor
performance. However, if you are using some sort of predictable
scheme for the id's and classes of your elements, you could do some
optimization if things get bad.
For example, if you have a table of 500 rows that all need an onclick
event attached, you can give them all the same class and then try out
some of the different "getElementsByClassName" functions to see what
performs the best. The css selector stuff is powerful, but it can be
slower then a simple function that only takes a css class and a root
node (for where to start the search). A mix of both would probably be
necessary for a page with a lot of events being attached.