1

これは重複しているように聞こえるかもしれませんが、フォーラムの質問を検索しましたが、探していたものが見つかりませんでした。

それで、私はしばらく読んでいます、そして、私はまだ次の状況について何をすべきかを決めることができません。スムーズなユーザーインターフェイスを必要とする1ページのWebサイト(私の最初ではない)を構築しているので、より良い、よりフレンドリーなナビゲーションのためにAJAXを使用してページをロードすることにしました。

私は使用しています:SmartAjax ; しばらくの間、それは私にとって十分でした。それはうまく機能し、私はそれで問題はありませんでしたが、コールバックとして多くのJavaScriptを処理するのに問題がありました。また、ウェブサイト全体に実装する際には、やるべきことがたくさんありました。

また、HTML5は1年前よりも安定しており、その機能のほとんどはほとんどのブラウザーで機能しているため(ただし、一部のブラウザーではまだポリフィルが必要です)、HTML5HistoryAPIの使用を開始することにしました。多くのウェブサイトがそれを使用していて、それを行うのは非常に簡単ですが、私がそれについて理解していないいくつかの側面があります。

したがって、これが私がそれについて知りたいことです:

  • 今ではすべてのブラウザでサポートされていますか?そして最も重要なのは、タッチデバイスとモバイルでサポートされるのでしょうか?
  • そのための特別なライブラリまたはフレームワークはありますか?
  • 小さなWebサイト(最大6ページ)に使用しても安全ですが、JavaScriptがたくさんありますか?
  • jQueryプラグインと組み合わせて使用​​すると動作しますか?
  • ハッシュバンとハッシュはどうですか?History APIを使用するのと同じではありませんか?違いは何ですか?

上記のポイントについて私が得たすべての助けと情報をいただければ幸いです。

4

2 に答える 2

3

ブラウザのサポート

それを忘れてください。IE9でさえサポートしていませんhistory.pushState。モバイルブラウザもあまり安全ではありません。ただし、この非互換性を開発者に対して完全に透過的にするライブラリ(以下を参照)があります。

としょうかん

まあ、純粋なHTML 5環境では、履歴APIは非常に単純です。他の人にとっては、history.jsライブラリはかなりの注目を集めており、それに加えて、古いハッシュ書き込みへの自動フォールバックを提供します

小さなウェブサイトで

それなら、JavaScriptと潜在的な状態を整理したほうがいいでしょう。でもそうなら問題ないと思います。

履歴とjQueryとプラグイン

I have used the two together in a couple of projects now. I have not yet found any problem with using jQuery and jQuery Plugins, except for - of course - the typical issues associated with Injected HTML (i.e. event handlers must be rebound; $(document).ready() might or might not work in some environments, etc).

Hashes vs. history.pushState

The Hash-Notation has been used as a workaround (or nowadays, fallback). It becomes unnecessary when using history.pushState.

What I have found to be the major difference is, that the URL in the address bar is always directly understandable by the server, especially for bookmarking or link-sharing purposes. If you had http://example.org/#/my/fancy/site, then your index page would have to parse the hash (via javascript, as you can't access the hash server-side), and then inject/redirect to my/fancy/site.

However, if using using history.pushState, the Browser's address bar shows http://example.org/my/fancy/site - which is directly routable.

(and, imagine spelling out a hash, or hash-bang URL to someone via phone!)

Hope that clarifies some or your doubts with history! I can strongly recommend History.js as library a of choice.

于 2012-05-22T21:42:08.817 に答える
1

I would prefer to use HTML5 History for browsers which support it (all current browsers and upcoming IE10), and use just static (non-Ajax) links for older ones. As browsers are updated, your site gets better automatically.

I wouldn't recommend using hash polyfills due to serious disadvantages of hashes (e.g. pointless referers that don't include hash part of URL, thus making stats rather useless).

于 2012-05-22T22:58:19.233 に答える