Feature: Enhance Blog Pagination with Dynamic Loading of Posts #307
+74
−2
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This pull request introduces dynamic loading for paginated blog posts, improving user experience (UX) by avoiding full page reloads when navigating through paginated content. Additionally, it ensures the browser's URL reflects the current page state, even when navigating with the browser's back and forward buttons. This enhancement significantly improves the UX for navigating paginated blog posts by leveraging dynamic loading and effective URL management, while maintaining compatibility for users without JavaScript.
Changes:
Dynamic Loading of Blog Posts:
URL Management:
Back/Forward Navigation Handling:
Graceful Fallback for No-JavaScript Users:
New File:
blog/loadMorePosts.js
:File Changes:
blog/index.html
:loadMorePosts.js
.Demo Videos:
Current/Before: Jarring UX with Full Page Reloads
current.mov
Dynamic Loading: First Few Pages
first-few-pages.mov
Dynamic Loading: Last Few Pages
last-few-pages.mov
No-JavaScript Fallback - Demonstrates the fallback behavior when JavaScript is disabled.
noscript.mov
Motivation:
This enhancement aims to provide a smoother and more seamless UX for users navigating through paginated blog posts. By dynamically loading posts and managing the URL state, users can enjoy uninterrupted browsing, and the navigation experience remains intuitive and consistent.
Implementation Details:
Dynamic Loading:
loadMorePosts.js
script listens for clicks on the "See more posts" button, prevents the default link behavior, and fetches the next page of posts asynchronously.URL Management:
history.pushState
to reflect the current page state after loading new posts.Back/Forward Navigation Handling:
popstate
event to treat back/forward navigation as a page reload, ensuring the correct state of posts is fetched.No-JavaScript Fallback:
<noscript>
tag to provide a fallback link for users with JavaScript disabled.