history.js README

The project's README from github.com/browserstate/history.js. As one markdown file: README.md.

Memo

While there are some legitimate bugs and differences in state handling even in modern browsers, they are relatively small enough now that you can just use the native HTML5 History API. If you intend to support legacy browsers, then History.js is your bet.

This notice is here as History.js does not receive enough funding to be maintained, so it exists only in legacy condition for legacy browsers. Perhaps it still works for modern browsers, but it could really do with maintenance. Maintenance is very difficult as the library requires manual testing in HTML5 and HTML4 modes, and for each adapter, and for each browser. So that means 2^(# of adapters)^(# of browsers and their versions) tests that need to be run by a human. Tests need to be run by a human as certain failures require browser interactions, such as navigating from the test suite to a different domain and back again, or clicking the physical back buttons, or checking if the physical back buttons actually work. This takes a lot of time.

Despite History.js being one of the most popular JavaScript libraries there is, and has been used by even multi-million-user companies in its time - the reality of economy and company practices seems to be that companies prefer to fork their own internal versions and fix locally with their own devs rather than fund open-source maintainers what they would pay their own devs to make things better for everyone, including themselves, which would be cheaper - but no, that would require too many tiers of company approval that don't understand the need.

As such, if you are an open-source developer, I'd recommend just working on open-source projects that are paid for by your own consulting work or your own company (e.g. every successful open-source project). As otherwise, when they become popular, you better hope they are easily maintainable and testable, otherwise the cost of maintenance is higher than the free time of the maintainers.

So with all that said, this repo still exists for archival purposes, legacy browsers, and a hub for anarachistic issue & fork maintenance.

Cheers, Benjamin Lupton, founder of Bevry, creator of History.js

Welcome to History.js
v1.8b2, June 22 2013

Slack community badge Patreon donate button Gratipay donate button Flattr donate button PayPal donate button Bitcoin donate button Wishlist browse button

News

History

See the HISTORY.md file for a detailed list of features, changes, solved issues and bugs

Involve

Please create an issue if something doesn't work or if there is a browser specific bug. I'll try to fix it as soon as possible. Please send me your Pull requests if you have a nice solution! I'm also going to review old issues in balupton's repository and try to solve them too.

Aims

Quick Install

Via Ajaxify Script

To ajaxify your entire website with the HTML5 History API, History.js and jQuery the Ajaxify script is all you need. It's that easy.

Via Ajaxify Extension

If you don't have access to your server, or just want to try out the Ajaxify script first, you can install the History.js It! Google Chrome Extension to try out History.js via Ajaxify on select websites without actually installing History.js/Ajaxify on your server.

Via Ruby On Rails Gem

If you are using Rails, then the easiest way for you to try History.js would be to use Wiselinks gem. Wiselinks integrates into Rails application and allows you to start using History.js with three lines of code.

Direct Install

Working with History.js directly

(function(window,undefined){

	// Bind to StateChange Event
	History.Adapter.bind(window,'statechange',function(){ // Note: We are using statechange instead of popstate
		var State = History.getState(); // Note: We are using History.getState() instead of event.state
	});

	// Change our States
	History.pushState({state:1}, "State 1", "?state=1"); // logs {state:1}, "State 1", "?state=1"
	History.pushState({state:2}, "State 2", "?state=2"); // logs {state:2}, "State 2", "?state=2"
	History.replaceState({state:3}, "State 3", "?state=3"); // logs {state:3}, "State 3", "?state=3"
	History.pushState(null, null, "?state=4"); // logs {}, '', "?state=4"
	History.back(); // logs {state:3}, "State 3", "?state=3"
	History.back(); // logs {state:1}, "State 1", "?state=1"
	History.back(); // logs {}, "Home Page", "?"
	History.go(2); // logs {state:3}, "State 3", "?state=3"

})(window);

How would the above operations look in a HTML5 Browser?

  1. www.mysite.com
  2. www.mysite.com/?state=1
  3. www.mysite.com/?state=2
  4. www.mysite.com/?state=3
  5. www.mysite.com/?state=4
  6. www.mysite.com/?state=3
  7. www.mysite.com/?state=1
  8. www.mysite.com
  9. www.mysite.com/?state=3

Note: These urls also work in HTML4 browsers and Search Engines. So no need for the hashbang (#!) fragment-identifier that google "recommends".

How would they look in a HTML4 Browser?

  1. www.mysite.com
  2. www.mysite.com/#?state=1&_suid=1
  3. www.mysite.com/#?state=2&_suid=2
  4. www.mysite.com/#?state=3&_suid=3
  5. www.mysite.com/#?state=4
  6. www.mysite.com/#?state=3&_suid=3
  7. www.mysite.com/#?state=1&_suid=1
  8. www.mysite.com
  9. www.mysite.com/#?state=3&_suid=3

Note 1: These urls also work in HTML5 browsers - we use replaceState to transform these HTML4 states into their HTML5 equivalents so the user won't even notice :-)

Note 2: These urls will be automatically url-encoded in IE6 to prevent certain browser-specific bugs.

Note 3: Support for HTML4 browsers (this hash fallback) is optional - why supporting HTML4 browsers could be either good or bad based on my app's use cases

What's the deal with the SUIDs used in the HTML4 States?

Is there a working demo?

Download & Installation

Note: If you want to only support HTML5 Browsers and not HTML4 Browsers (so no hash fallback support) then just change the /html4+html5/ part in the urls to just /html5/. See Why supporting HTML4 browsers could be either good or bad based on my app's use cases

Get Updates

Get Support

Thanks! every bit of help really does make a difference!

Browsers: Tested and Working In

HTML5 Browsers

HTML4 Browsers

Exposed API

Functions

States

Adapter

Navigation

Debug

Options

Events

Known Issues

Notes on Compatibility

License

Licensed under the New BSD License
Copyright © 2014+ Bevry Pty Ltd [email protected]
Copyright © 2011-2013 Benjamin Arthur Lupton [email protected]

For support see the Getting Support section.

history.js (browserstate/history.js)

Searching Database…

What is this?A JavaScript library that makes the HTML5 History/State APIs (pushState, replaceState, onpopstate) work consistently in every browser: real URLs in HTML5 browsers, a hash-based fallback in old HTML4 ones.
Is this a framework I build my app on, or a library I drop into an existing page?A drop-in library: include one prebuilt script file and call History.pushState / History.replaceState in your own code. Adapters hook it into the framework (jQuery, MooTools, Prototype) your page already uses.
How do I add it to my site?Download the tar.gz or zip, upload it to your webserver and include the build matching your adapter in a script tag, or use the Ajaxify script to ajaxify a whole site at once. A 'History.js It!' Chrome extension lets you try it without touching your server.
Does it require jQuery, or can it run standalone?It runs standalone (a build 'for everything else' is included), plus adapters for jQuery v1.3+, MooTools v1.3+, Zepto v0.5+, Dojo v1.8+, ExtJS and Right.js v2.2+. Pick the file matching your page's framework.
Is it still maintained? Should I use it in a modern browser?Effectively no: the author says the native HTML5 History API is now good enough for modern browsers, and the library lives on 'only in legacy condition for legacy browsers'. Last release noted: v1.8b2, June 2013.
Who is it for today?Web developers who need working history and clean URLs even on legacy browsers. If you only target modern browsers, the README says to just use the native API.
Which browsers does it run in?HTML5 mode: Firefox 4+, Chrome 8+, Opera 11.5+, Safari 5+, iOS Safari 4.3+. HTML4 hash-fallback mode: IE 6-9 (10 tentatively), Firefox 3, Opera 10/11.0, Safari 4, older iOS. It is plain JavaScript, so the OS does not matter.
What do the URLs look like on old browsers?HTML4 browsers get hash URLs like www.mysite.com/#?state=2&suid=2, where the SUID suffix ties the hash to your state data and title. If an HTML5 browser opens that link, History.js quietly upgrades it to the clean non-hashed equivalent.
Do I still need the Google hashbang (#!) trick for search engines?No. The clean ?state= URLs also work in HTML4 browsers and search engines, so no hashbang fragment-identifier is needed.
What does its API look like?HTML5-style calls: History.pushState(data,title,url), History.replaceState(data,title,url) and History.getState(), plus back/forward/go navigation, a framework-independent History.Adapter, and a window.onstatechange event.
Is there a demo or tests to look at?Yes. After downloading, open the demo directory in your browser; the tests directory goes further and shows the full range of supported use cases.
Size
3 MB
Stars
10.6K
Updated
CommitNov 12
Age
15y
Commits · 90 Days