Mozilla.com

  1. MDC
  2. Strona główna
  3. Zasoby offline w Firefoksie

Zasoby offline w Firefoksie

UWAGA: Tłumaczenie tej strony nie zostało zakończone.
Może być ona niekompletna lub wymagać korekty.
Chcesz pomóc? | Dokończ tłumaczenie | Sprawdź ortografię | Więcej takich stron...

Ten artykuł obejmuje funkcje wprowadzone w Firefoksie 3

Firefox 3 implements much of HTML 5's support for offline caching of web applications' resources. This is done using the application cache -- a collection of resources obtained from a resource manifest provided by the web application.

Pamięć podręczna aplikacji

^ 

Uwaga: Firefox nie obsługuje obecnie różnicy wersji w zachowanych aplikacjach.

Ponieważ wiele aplikacji sieciowych może udostępniać zasoby (jak i udostępniać je również na tych samych identyfikatorach URI), każda aplikacja internetowa utrzymuje swoją własną pamięć podręczną. Jednakże, zasoby aplikacji są pogrupowane według ich zapisów URI, a także posiadają prostą stan aktualizacji. Stan aktualizacji jest na jednym z poniższych poziomów:

idle / bezczynny
Zasoby aplikacji nie są w danej chwili aktualizowane.
checking / sprawdzanie
Zasoby są sprawdzane pod kątem aktualności
downloading / ściąganie
Zasoby aktualizowane na podstawie zmienionych wykazów zasobów.

Uwaga dotycząca Firefoksa 3

Obecnie tylko wpisy do zasobów są obsługiwane. Firefox jeszcze nie wspiera opportunistic caching or cofanie wpisów; jednakże zaleca się, żebyś ciągle zapewniał białą listę, jeżeli to stosowne, dla przyszłej kompatybilności.

Zasoby

Pamięć podręczna zawiera zawsze przynajmniej jeden zasób, identyfikowany przez jego URI, z przynajmniej jednej z następujących kategorii:

Implicit entries
These are resources added to the cache because a top-level browsing context visited by the user included a document indicating that the resource was in its cache using its manifest attribute.
The manifest
This is the resource manifest itself, loaded from the URI specified in an implicit entry's html element's manifest attribute. The manifest is downloaded and processed during the application cache update process. Implicit entries must have the same scheme, host, and port as the manifest.
Explicit entries
These are resources listed in the cache's manifest.
Fallback entries
These are resources that were listed in the cache's manifest as fallback entries. Nie jest jeszcze wspierana przez Firefoksa.
Opportunistically cached entries
These are resources whose URIs matched an opportunistic caching namespace when fetched, and were therefore cached automatically into the application cache. Nie jest jeszcze wspierana przez Firefoksa.
Dynamic entries
These are resources added programmatically using the add() method.

The online whitelist

The online whitelist may contain zero or more URIs of resources that the web application will need to access off the server rather than the offline cache. This lets the browser's security model protect the user from potential security breaches by limiting access only to approved resources.

^ 

Uwaga: The online whitelist is not used in Firefox 3; however, you should provide one if needed anyway, both to provide compatibility with future versions of Firefox as well as with other browsers' implementations of offline resource support.

The cache manifest

Cache manifest files must be served with the text/cache-manifest MIME type, and all resources served using this MIME type must follow the syntax for an application cache manifest, as defined here. Cache manifests are UTF-8 format text files and may, optionally, include a BOM character. Newlines may be represented by line feed (U+000A), carriage return (U+000D), or carriage return and line feed both.

The first line of the cache manifest must consist of the string "CACHE MANIFEST" (with a single U+0020 space between the two words), followed by zero or more space or tab characters. Any other text on the line will be ignored.

The remainder of the cache manifest must be comprised of zero or more of the following lines:

Blank line
You may use blank lines comprised of zero or more space and tab characters.
Comment
Comments consist of zero or more tabs or spaces followed by a single "#" character, followed by zero or more characters of comment text. Comments may only be used on their own lines, and cannot be appended to other lines.
Section header
Section headers specify which section of the cache manifest is being manipulated. There are three possible section headers:
Section header Description
CACHE: Switches to the explicit section. This is the default section.
FALLBACK: Switches to the fallback section.

^ 

Uwaga: The fallback section is not yet supported by Firefox, and will be ignored.

NETWORK: Switches to the online whitelist section.

^ 

Uwaga: The online whitelist section is not yet supported by Firefox, and will be ignored; however, providing an appropriate online whitelist is strongly recommended.

The section header line may include whitespaces, but must include the colon in the section name.
Data for the current section
The format of data lines varies from section to section. In the explicit section, each line is a valid URI or IRI reference to a resource to cache. Whitespace is allowed before and after the URI or IRI on each line.

Cache manifests may switch back and forth from section to section at will (so each section header can be used more than once), and sections are allowed to be empty.

^ 

Uwaga: Relative URIs are relative to the cache manifest's URI, not to the URI of the document referencing the manifest.

Prosty wykaz pamięci podręcznej

Poniżej znajduje się prosty wykaz pamięci podręcznej zmyślonej strony o adresie foo.com.

CACHE MANIFEST
# v1
# To jest przykładowy komentarz.
http://www.foo.com/index.html
http://www.foo.com/header.png
http://www.foo.com/blah/blah

W tym przykładzie nie ma sekcji nagłówkowej, dlatego wszystkie linijki danych są zawarte w otwartej sekcji.

Komentarz z linijką "v1" znajduje się tam z dobrych powodów. Ponieważ pamięć podręczna jest aktualizowana tylko wtedy, gdy zostanie zmieniony wykaz(manifest), to, jeżeli zmienisz zasoby (na przykład zmieniając obrazek header.png), wystąpi potrzeba zmiany pliku wykazu, by powiadomić przeglądarkę o potrzebie odświeżenia pamięci podręcznej. Można tego dokonać różnymi sztuczkami na wykazie, lecz zawarcie jego numeru wersji jest dobrym sposobem do osiągnięcia tego efektu.

Aby zlecić Firefoksowi użycie zapamiętania zasobów offline dla podanej strony, należy użyć atrybutu manifest(z ang. wykaz) w elemencie html, jak to uczyniono poniżej:

<html manifest="http://www.foo.com/cache-manifest">
  ...
</html>

Proces aktualizacji

  1. Kiedy Firefox napotka dokument, który posiada atrybut manifest, wysyła event(zdarzenie/wyjątek) checking do obiektu window.applicationCache, wtedy dostaje się do pliku wykazu, podążając według odpowiednich reguł buforowania HTTP. Jeżeli obecnie zapamiętana kopia wykazu jest aktualna, to event(zdarzenie/wyjątek) noupdate jest wysyłane do applicationCache i proces aktualizacji jest zakończony.
  2. If the manifest file hasn't changed since the last update check, again, the noupdate event is sent to the applicationCache, and the update process is complete. Again, this is why if you change the resources, you need to change the manifest file so Firefox knows it needs to re-cache the resources.
  3. If the manifest file has changed, all files in the manifest -- as well as those added to the cache by calling applicationCache.add() -- are fetched into a temporary cache, following the appropriate HTTP caching rules. For each file fetched into the cache, a progress event is sent to the applicationCache object. If any errors occur, an error event is sent, and the update halts.
  4. Once all the files have been successfully retrieved, they are moved into the real offline cache atomically, and a cached event is sent to the applicationCache object.

Funkcje jeszcze niezaimplementowane w Firefoksie

Ponieważ szkic standardu HTML 5 był jeszcze w trakcie zmian w czasie, gdy zbliżała się data zamrożenia funkcjonalności Firefoksa 3, część możliwości pamięci podręcznej offline nie została zaimplementowana:

  1. Szkic specyfikacji WHATWG wskazuje, że wszystkie zapytania powinny przychodzić z pamięci podręcznej offline, kiedy jest dostępna, nawet jeśli przeglądarka jest w trybie online. Obecnie Firefox ma dostęp do pamięci podręcznej offline jedynie, gdy jest w trybie offline. Z tego powodu również biała lista online nie jest jeszcze wspierana.
  2. Firefox doesn't currently maintain separate caches for each web application. Applications should avoid sharing resources between different manifests unless they're not concerned about conflicting versions of the resources. In general, though, applications should maintain per-application copies of each resource.
  3. Firefox doesn't yet support opportunistic caching or fallback entries.

Page last modified 23:00, 6 sie 2008 by Mgjbot

Plików (0)