Using absolute URLs in JQM
I have an existing web project with Java on the backend. It uses absolute paths for linking between pages.
I'm currently converting the project to use jQuery Mobile. I first tried to use relative urls, but changing the whole url structure in the project wasn't that easy, especially when many of the urls are generated on the fly, and finding the correct relative path in respect to the currently displayed page was a bit complicated (mainly because of our own AJAX calls that target different URL endpoints on the server than the page itself).
So I started thinking if it was possible to change the JQM code to work with absolute urls only. I'm currently trying to change usage of location.hash to location.href to make it rewrite the whole path in the URL instead of just the part after hash. Did anyone of you try it? Is it possible?
Sidenote: Why does JQM have the relative URL model with hashes in the first place? Is it to support backtracking? It doesn't seem to me very likely, as they keep the whole history stack in the urlHistory
field. Or is it just to handle relative links inside the pages? In that case, wouldn't it be worth considering to create two URL modes in JQM and let the user of the framework decide wh开发者_JAVA百科ich one to use (probably in 'mobileinit'): one if the implementation uses relative links (i.e. a static HTML project where JavaScript does all the work), and another for absolute links (i.e. a dynamic web project where much of the computation is done on the server)? It could also solve the issue with stupid URLs like http://server.com/folder1/folder2/page.html#../../index.html
...
Why does JQM have the relative URL model with hashes in the first place? Is it to support backtracking?
My understanding of why they use # to navigate is because they want the page to feel more native. Having a single page holding everything and using smooth transitions between "pages" gives this illusion instead of having a link clicked and then waiting for the entirely new page to be downloaded.
Regarding trying to retrofit a website to work with jquery mobile, I saw on some blog suggesting:
<script>
$(document).ready(function() {
// disable ajax nav
$.mobile.ajaxLinksEnabled = false;
});
</script>
So far I haven't gotten this to work with my existing page but it logically makes a bit of sense in that jqm will stop trying to convert your links to ajax requests like you suggested above. This means you forfeit some transitions when clicking links but it might save quite a bit of time to get a mobile page up...just wish I could get it to actually work.
精彩评论