Jump to content

Ajax Vs Raw Php


hybrid kill3r
 Share

Recommended Posts

The point of AJAX is to load only specific data, rather than having the reload a whole page just to change one part of it. AJAX saves bandwidth, overall.A good AJAX application should be able to degrade gracefully without trouble if Javascript is disabled.

Link to comment
Share on other sites

Calling PHP to create a page or to create an Ajax message are both http requests, just going to different slots on the browser.You may as Ingolme says save bandwith on pages that only have bits changing (eg paging item lists). For me, an overhead Ajax can cut out is the transport and storage of state information. In a high load site you may have to read/write session data to a database, and it would be useful to minimise or eliminate such calls.Browsers are typically many times more powerful than servers - you'll hardly browse a web site whilst playing Quake.

Link to comment
Share on other sites

A good AJAX application should be able to degrade gracefully without trouble if Javascript is disabled.
is that really an AJAX application?what you describe sounds much more like a server application than AJAX.i don't understand how one could have a javascript-based application without using javascript...OP:you should try to get the HTML out as fast as possible.that means initially bundling as much instant info as possible to minimize further HTTP transactions and the associated ping delay.on the other hand, if the info you need is the result of a complicated database query, or data that's remotely loaded from a slow server, it makes sense to defer that lockup until it's needed. you can multitask a lot better using the new defer attribute on script tags to allow the browser to paint the interface before tha data arrives.all the newer browsers and old IEs support the defer attribute, and it lets you load several sources at once.normally, the browser waits on every hard-coded <script> tag to finish loading before drawing the page...there is no universal answer to your question; you have to weigh the factors and design accordingly for your situation/needs.i would recommend checking out the yahoo performance recommendations for some good information on the subject.there's also a few videos on google video ("javascript performance") that discuss the nitty-gritty of applying those factors to your site.also consider is the fact that there's always at least as many client CPUs available as there are server CPUs (give or take a multi-core), so it makes sense to put those 2.6Ghz dummy terminals to work on processor-intensive calculations. Javascript probably runs tasks faster than many popular server languages would, especially the newer versions of chrome, safari, and firefox's javascript engines. it's also free for you, make them do the work as you quickly serve static text files.the best generic way overall to accomplish better performance is to test.time, adjust, repeat.
Link to comment
Share on other sites

About degrading gracefully. I think Ingolme refers to basic AJAX functionality where maintaining state is a luxury, not a necessity -- where the data to be submitted is entered into a form (or is already there in hidden elements) and in the absence of Javascript, the form submits like a traditional form. Say, for example, you have an AJAX chatroom. Reloading the page for every transmission would be inconvenient, but it would not have to ruin the chat.On the other hand, people are writing more and more complex webapps in which maintaining state is critical, or where the absence of Javascript just makes the thing pointless. Imagine a pretty complex spreadsheet that requires several hundred entry fields, and a new calculation is performed whenever a field is updated. This does not lend itself well to a form post on every update.I think we're at a place now where many developers can simply say, if Javascript is disabled, this app is not for you, and users will be choose to make the tradeoff or not.The bigger point is this. If a document *can* be written so that AJAX degrades to a traditional form post, it probably should be. If not, not.

Link to comment
Share on other sites

A good AJAX application should be able to degrade gracefully without trouble if Javascript is disabled.
A really good ajax application tells people to come back when they have Javascript enabled.
I think we're at a place now where many developers can simply say, if Javascript is disabled, this app is not for you, and users will be choose to make the tradeoff or not.
Beat me to it.The vast majority of people have Javascript enabled, for several years only 5%-10% of people have had it disabled.
Link to comment
Share on other sites

I understand that a full web application requires Javascript to be enabled. But when it comes to simple websites with dynamic content, I think developers still should think about making the sites work correctly without Javascript.

Link to comment
Share on other sites

Which would be faster... including PHP scripts on pages, or loading the php scripts with ajax? i hope that makes sense.
Relative to which point in time?Initially, including PHP scripts would be faster, as you have everything processed once (one HTTP request, one PHP initialization, etc.). If you remain on the same webpage, and have bits of data changing constantly, making the user refresh the whole page just for those small bits is going to be slower than calling those special PHP scripts with AJAX.However, preserving the state (i.e. keeping the "back" button working) is only available in the latest IE and FF browsers, and therefore, if you have large parts of data that need refreshing, and to which the user may want to go navigate back and forth to, using plain PHP page loading is still highly recommended. Edited by boen_robot
Link to comment
Share on other sites

a lot of people have CSS that don't have javascript.would it be possible to use stay-open connections (comet), in conjunction with CSS, ex:

  a.uiWidget-01:active{background: url('handleInteraction.php?action=uiWidget-01');}

and returning CSS, ex:

a.uiWidget-01:before {content:string('this is an updated value');} @import url("nextCometTransaction.php");

to update the page content in reaction to user behavior without javascript and without refreshing?

Edited by rnd me
Link to comment
Share on other sites

I understand that a full web application requires Javascript to be enabled. But when it comes to simple websites with dynamic content, I think developers still should think about making the sites work correctly without Javascript.
I agree. A lot of developers seem to gripe about browsers not complying with standards and silly people fearing whatever ActiveX is that IE keeps warning them about, but there are a good many dynamic features that can be accounted for on the server side. Browser detection via PHP is not a problem, and you can create alternative content / import different style sheets easily in response. I am one of those weird beings who uses AOL, and I appreciate that most sites work on it, but sometimes it takes a bit of effort to get them to. The site I'm developing at the moment has been a headache for a few days but it now displays nearly as well in AOL as it does elsewhere thanks to PHP (though I will be posting about my strange problem in the CSS forum in a moment).As for JavaScript, a nice noscript comment advising people about the safey of scripts and an indication that some features might not be as wondrous as they could be is probably enough. Those who know enough to have disabled JavaScript know that it's not something to be feared, and those old enough to wonder, "What the heck is JavaScript?" will probably holler on their son/daughter to decipher it for them, and with any luck they will know what it means.
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...