[nycphp-talk] PHP html DOM manipulation
Rob Marscher
rmarscher at beaffinitive.com
Wed Aug 10 11:36:18 EDT 2011
>> 2) After the entire page is loaded, an onDomReady event is fired which find
>> all href links with a rel attribute of lightbox[x] where x is some text.
>> The javascript code will then check to see if there is a thumbnail for the
>> image[by checking for the same image name in a subdirectory called thumbs -
>> if so, it changes the innerHTML to an img tag pointing to the thumbnail and
>> sets the alt attribute for the thumbnail to the original text for the link.
On Aug 10, 2011, at 10:57 AM, John Campbell wrote:
> This is a problem. For javascript to detect if an image exists on the
> server, it must do a HTTP request which takes ~100ms. For PHP to
> check if that image exists on the same machine, requires 1 sys call or
> about ~0.01ms. It sounds like you have a bad lightbox implementation.
> The page should already know if the thumbnail exists, and if a
> lightbox is possible when the html is sent.
I think I've seen some lightbox versions that can work like Gary described, but they can usually also be configured to work off of existing thumbnail images that are already in the html. For this task, I think you would be better off just outputting the thumbnails in the html (in your template or however you do it), rather than trying to parse the DOM after the fact and add them in. A viable use for DOM manipulation in php is when you need to work with html not under your control (for example, read an html file off an external server and extract data from it).
More information about the talk
mailing list