Welcome Guest, Not a member yet? Register   Sign In
Best way to set up AJAX/JQuery process?
#12

(This post was last modified: 03-01-2015, 11:25 AM by spjonez.)

(02-19-2015, 01:47 PM)mwhitney Wrote: If the purpose of a table is to display data, how is an empty table not broken (except in the very strict sense that the spec allows a table to contain zero or more rows)?

The table is only empty until it's populated. Empty != broken. If you're concerned about seeing an empty header/footer hide the table with CSS then flip it's display once the row data is available.

(02-19-2015, 01:47 PM)mwhitney Wrote: I understand the desire not to duplicate code between PHP and JavaScript. However, as CroNiX mentioned, you can also load the data into a partial view in PHP and send it over, leaving the script to simply insert it into the DOM. Additionally, you could load the same partial view and insert the initial data set on the server side before sending the page without duplicating any code.

You could but it's faster to defer the search query until after the page loads, trigger a submit on the form on DOM ready and inject the results inline using a DOM fragment to batch insert rows in one operation. This also has the benefit of you only having one set of code to render the table (your AJAX stuff) and puts less strain on your server since it splits up requests.

(02-19-2015, 01:47 PM)mwhitney Wrote: The points I'm trying to make are:
- JavaScript should not be required to access your content, and
- triggering a second request on page load is not usually as efficient as it seems.

JS is required for just about everything in the modern web. Triggering a second request is both faster and increases perceived performance as time between page changes is less. Consider a page that shows search results on load. The page takes 0.5s to load and the search query takes an additional 0.5s to run.

Situation A:
- User clicks a link to the page, user waits for 1s to see the page fully rendered.

Situation B:
- User clicks a link to the page, sees page content after 0.5s then sees results fill in the table. Since your AJAX call is triggered on DOM ready the request is sent before the browser starts to paint the page. As the page is being drawn your search request is sent and returned in what appears to be less than 0.5s since it starts before painting begins.

Visually, it appears your site is almost twice as fast using a deferred load. It's the same psychological effect as sitting on hold on the phone. Waiting for 1m seems like 10m.
Reply


Messages In This Thread
RE: Best way to set up AJAX/JQuery process? - by spjonez - 03-01-2015, 11:18 AM



Theme © iAndrew 2016 - Forum software by © MyBB