- Unclear if the above code is the code that is objectionably slow,
or some other code you haven't shown us.
- First, tell us just what you mean by "lazy load".
Usually, that is taken to mean loading as the user scrolls, so that it
fetches a few more items beyond what can be seen, and as the user
scrolls, it gets more.
That's not easy to do right, and if that is what you want, I
would look for a plugin.
There is this one, but it only works with a very old version of
jQuery Mobile:
But I'm guessing that's not what you mean by "lazy
load", because I see you are using data-filter, and so you need
to have all of the items for the filter to work. It wouldn't make
sense to only load more items once the user scrolls.
- Next, determine the cause(s) of the delay. Is it because your
website takes some time to respond, or because it takes a long time to
display the data once the browser has it? Use your browser's
inspection tools to see the timeline.
- How many items in a list? listview is not a good choice for
long lists. You will get much better performance with some plain
HTML and CSS, especially if there are links in the list.
- I see a suspicious bit of code above. At line 36 you
empty #posts.
It looks to me that for every post, you empty #posts, and populate
it. The user will only see the last one, and you will have
needlessly emptied and re-populated the element for each item. The
user will never see more than one item in the list.
- If you intend on fetching each item separately from your
server, realize that while the user may see results sooner, overall
it will take even longer (MUCH longer) to populate the list.
- Don't use inline onclick! It is not 1995! It bloats your
page size unnecessarily. Just write a click delegation in JS.
- Remove the data-prefetch. I
don't know if it might cause any trouble, but in any case it is
meaningless. You are telling it to "prefetch" a page that is
already "fetched". data-prefetch is for
when you use single-page documents.