I'm using some basic jQuery to speed up my site by replacing the content via AJAX rather than fully reloading the page (similar to what Turbolinks does):
$("nav").delegate("a", "click", function() {
href = $(this).attr('href');
history.pushState(null, null, href);
$('#main').load(href + " #main");
return false;
});
The problem I'm having, though, is that the relative links on my /portfolio
page fail. For example, I have <img src="website.jpg">
which is located at /portfolio/website.jpg
, but throws a 404 because .load()
is looking for /website.jpg
.
I know that making the image paths absolute will work, but is there some way to fix this with JavaScript? And why doesn't jQuery handle this? Are relative links bad practice?