What is the best way to AJAXize existing wordpress templates to prevent having to load a whole new page?
-
the method should allow for replacement of just the page content (text images etc) and not the entire template all over again.
-
Answer:
I'll need a bit more info -- what exactly are you trying to accomplish here (the end goal)? e.g. Why would you want to replace a page's content without a reload? ---------------------- OK. That helps. AJAX comment plugins are plentiful if you want to avoid page reloads there. If you want to swap everything you're looking at a real headache in that WordPress themes are not designed to be rendered client side. But if you really wanted to do it, and every page basically uses the exact same template... you'd want to look into a plugin like JSON API (or similar): http://wordpress.org/extend/plugins/json-api/ WIth that you could get all the new post data via AJAX, and then write a (theme specific) rendering function that would swap all the DOM element's content to render the new post within the old one. You'll also want to use HTML pushState() to modify the browser history and URL to not break usability there (e.g. bookmarking, back button). http://diveintohtml5.info/history.html And then you have the sidebars to deal with -- if they are site wide and never change per post/page, you can leave it, otherwise you may need to write an AJAX call to return that as a big HTML fragment and do a wholesale swap of the content each sidebar. Again this would be theme specific as different sidebars can be registered by themes. And the menu... which would need class updates for current page ancestor, parent, etc. And the footer, if that changes at all based on the page shown. If you're head is hurting by now (mine is) you can see that you're basically rewriting the browser in JavaScript and the parts of the page you're not replacing are actually pretty insignificant as far bas bandwidth and load time are concerned (some sites like blogs may be mostly static except for post content, but not WP as a CMS ones). Between caching (server side), using a CDN, and the browser's internal cache (client side) I'm not sure if it's quite worth all this work to save transmitting a few bytes of HTML over the wire for a page load (comments do make sense to do via AJAX though). This would break in older browsers (e.g. they'll have to fallback to the traditional page request as they don't support the history API, or you'd have to use those nasty hashbang URLS which are widely considered a usability nightmare). Gist It can be done, but site speed is mostly solvable in other ways (caching, CDN, server performance optimization). AJAX comments are a solved problem. Facebook is a web application tuned specifically for this purpose (and is really more analogous to AJAX comments). Getting WP to behave similarly (outside a very narrow scope) is a very difficult task (at present). Good luck, please post your results if you're able to pull it off!
Nick Ciske at Quora Visit the source
Related Q & A:
- What is the best way to distribute an audio/video feed from a computer to TVs over existing indoor coax cable?Best solution by Audio-Video Production
- What is the best way to travel in new south wales?Best solution by Yahoo! Answers
- What is the best way to get to New York City from Philadelphia?Best solution by Yahoo! Answers
- What is the best way to find new members for a yahoo group?Best solution by Yahoo! Answers
- What is the best way to negotiate a salary for a new position?Best solution by Yahoo! Answers
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.