History.js Deployment and Usage Guide
Prerequisites
- Runtime: A modern web browser (Chrome 5+, Firefox 4+, Safari 5+, Opera 11.5+, Internet Explorer 10+) for HTML5 History API support
- JavaScript Framework: Choose one of the supported frameworks:
- jQuery (1.3+)
- MooTools (1.2+)
- Prototype (1.6.0.3+)
- Ext JS (3.0+)
- Dojo (1.4+)
- Right.js (2.2+)
- Zepto (1.0rc1+)
- Legacy Browser Support: For HTML4 browsers, no additional prerequisites needed (uses hash fallback)
Installation
-
Clone the repository:
git clone https://github.com/browserstate/history.js.git cd history.js -
Include the appropriate adapter in your HTML file based on your JavaScript framework:
For jQuery:
<script src="path/to/jquery.js"></script> <script src="path/to/scripts/bundled/html4+html5/jquery.history.js"></script>For MooTools:
<script src="path/to/mootools.js"></script> <script src="path/to/scripts/bundled/html4+html5/mootools.history.js"></script>For other frameworks, replace the adapter file accordingly.
Configuration
- No environment variables or API keys required
- No configuration files needed
- Optional: To remove HTML4 support for modern browsers only:
// Remove HTML4 support History.options.disableHashFallback = true;
Build & Run
Development
-
Include History.js in your HTML file:
<!DOCTYPE html> <html> <head> <script src="path/to/your-framework.js"></script> <script src="path/to/scripts/bundled/html4+html5/jquery.history.js"></script> <script> $(document).ready(function() { // Your History.js code here History.pushState({state: 1}, "Title", "/new-url"); }); </script> </head> <body> <!-- Your content --> </body> </html> -
Test in browser:
- Open the HTML file directly in your browser
- Use browser developer tools to verify History API calls
- Test back/forward navigation
Production
-
Minified version: Use the minified adapter files for production:
<script src="path/to/scripts/bundled/html4+html5/jquery.history.min.js"></script> -
CDN: Consider using a CDN for faster loading:
<script src="https://cdn.jsdelivr.net/npm/history.js@1.8b2/scripts/bundled/html4+html5/jquery.history.min.js"></script>
Deployment
History.js is a client-side JavaScript library, so deployment is straightforward:
-
Static Hosting:
- Deploy your HTML files to any static hosting service
- Recommended platforms: Netlify, Vercel, GitHub Pages, AWS S3/CloudFront
-
Server-side Integration:
- If using server-side rendering, ensure server can handle the URLs used by History.js
- Configure server to return the same HTML file for all routes that History.js manages
-
Example Netlify deployment:
# netlify.toml [[redirects]] from = "/*" to = "/index.html" status = 200
Troubleshooting
Common Issues and Solutions
-
History API not working in older browsers:
- Issue: History API not supported in IE9 and below
- Solution: History.js automatically falls back to hash-based navigation for these browsers
-
State change events not firing:
- Issue:
onpopstatenot working as expected - Solution: Ensure you're using the correct adapter for your framework and check browser console for errors
- Issue:
-
Cross-domain navigation issues:
- Issue: Navigating to different domains breaks History.js
- Solution: History.js handles cross-domain navigation, but ensure your server configuration allows it
-
State data not persisting:
- Issue: State data lost after page refresh
- Solution: History.js stores state in browser history; ensure you're using
pushState/replaceStatecorrectly
-
jQuery adapter conflicts:
- Issue: Conflicts with other jQuery plugins
- Solution: Use jQuery's
noConflictmode if needed:var $j = jQuery.noConflict(); $j(document).ready(function() { // Your History.js code });
Testing
- Manual testing: Test in multiple browsers including legacy ones
- Automated testing: Use tools like Selenium or Cypress for cross-browser testing
- Check browser support: Verify HTML5 History API support using:
if (window.history && window.history.pushState) { console.log("HTML5 History API supported"); }
Performance Considerations
- Bundle size: Choose only the adapter you need
- Minification: Use minified versions in production
- CDN: Consider using a CDN for faster global delivery
- Caching: Set appropriate cache headers for static assets
Legacy Browser Support
- IE8/IE9: History.js provides hash fallback automatically
- Mobile browsers: Test on iOS Safari and Android browsers
- Feature detection: History.js includes feature detection for graceful degradation
For more detailed information, refer to the History.js Wiki and the HTML5 History API documentation.