I want to convert my website into a single page app. This function does the trick:$(document).ready(function(){       $(body).delegate(a, click, function(){        var href = $(this).attr(href);                    $.get(href,function(data){            var newDoc = document.open(text/html, replace);            newDoc.write(data);            newDoc.close();        });        return false;    });});Assuming I have no redirects other than <a> tags, it should work fine, right? It feels so wrong and yet so right...
Converting a Website Into a Single Page App
javascript;jquery;html
It will work, but consider why you might be doing SPA's:No more full screen flickering, better user experienceKeep your state on the browser side instead of pingponging it between server & browserLess network traffic if you only request for data & do the rendering with templates in JSWith your approach, You are rebuilding the whole DOM from scratch everytime, so there will still be flickering.With script tags being replaced while JS is still running, I dont even want to think about what mess your state will be in ;)You are still fetching data + layout from the server, so not gaining anything from a network perspective.Furthermore, you run the risk of memory leaks, which happen like this:Add any listener to your DOMForget to unbind that listener when the user clicks a linkNew content is loaded, old DOM is gone, but that old listener is still out there