From 25debec66a35fc20db84bf5aca690489b5bec306 Mon Sep 17 00:00:00 2001 From: julieng Date: Sun, 11 Apr 2021 16:03:26 +0200 Subject: Archiving HTML - Using the Application cache --- .../html/using_the_application_cache/index.html | 338 --------------------- 1 file changed, 338 deletions(-) delete mode 100644 files/ko/web/html/using_the_application_cache/index.html (limited to 'files/ko') diff --git a/files/ko/web/html/using_the_application_cache/index.html b/files/ko/web/html/using_the_application_cache/index.html deleted file mode 100644 index e32a89c21a..0000000000 --- a/files/ko/web/html/using_the_application_cache/index.html +++ /dev/null @@ -1,338 +0,0 @@ ---- -title: 애플리케이션 캐시 사용하기 -slug: Web/HTML/Using_the_application_cache -translation_of: Web/HTML/Using_the_application_cache ---- -
{{DefaultAPISidebar("App Cache")}}{{SecureContext_Header}}{{Deprecated_Header}} -
-

Using the application caching feature described here is at this point highly discouraged; it’s in the process of being removed from the Web platform. Use Service Workers instead. In fact as of Firefox 44, when AppCache is used to provide offline support for a page a warning message is now displayed in the console advising developers to use Service workers instead ({{bug("1204581")}}).

-
-
- -

소개

- -

HTML5 는 웹기반의 애플리케이션들이 오프라인에서도 실행되도록 해주는 애플리케이션 캐시 메카니즘을 제공한다. 개발자는 브라우저에 캐시되어 오프라인 사용자가 사용할 수 있도록 자원을 지정하기 위하여 애플리케이션 캐시(앱 캐시) 인터페이스를 사용할 수 있다. 캐시된 애플리케이션은 사용자가 오프라인 상태에서 새로고침을 클릭할 때 올바르게 불러와서 작동한다.

- -

애플리케이션 캐시를 사용하는 것은 애플리케이션에 다음과 같은 이익을 줍니다:

- - - -

애플리케이션 캐시의 작동 방식

- -

애플리케이션 캐시 활성화 하기

- -

애플리케이션에서 애플리케이션 캐시를 활성화 하기 위해서, 먼저 당신의 애플리케이션의 페이지들의 {{HTMLElement("html")}} 엘리먼트에 {{htmlattrxref("manifest", "html")}} 속성을 추가할 필요가 있습니다:

- -
-
<html manifest="example.appcache">
-  ...
-</html>
-
- -

manifest 속성은 캐시 매니페스트 파일을 가르키며, 이는 브라우져가 당신의 애플리케이션을 위해 캐싱할 리소스(파일들)의 리스트인 텍스트 파일입니다.

- -

당신은 반드시 manifest 속성을 당신 애플리케이션의 캐싱하길 원하는 모든 페이지마다 포함시켜야합니다. The browser does not cache pages that do not contain the manifestattribute, unless such pages are explicitly listed in the manifest file itself. You do not need to list all the pages you want cached in the manifest file, the browser implicitly adds every page that the user visits and that has the manifest attribute set to the application cache.

- -

몇몇 브라우저들은(e.g., Firefox) 애플리케이션 캐시를 사용하는 애플리케이션을 처음 로드할 때 알림을 띄웁니다. 알림은 다음과 같은 메시지를 표시합니다:

- -

해당 사이트가 (www.example.com) 오프라인 사용을 위해 데이터를 저장을 요청합니다. [예] [이 사이트에서 사용안함] [나중에]

- -

The term "offline(-enabled) applications" sometimes refers specifically to applications that the user has allowed to use offline capabilities.

- -

documents 불러오기

- -

The use of an application cache modifies the normal process of loading a document:

- - - -

The process for loading documents and updating the application cache is specified in greater detail below:

- -
    -
  1. When the browser visits a document that includes the manifest attribute, if no application cache exists, the browser loads the document and then fetches all the entries listed in the manifest file, creating the first version of the application cache.
  2. -
  3. Subsequent visits to that document cause the browser to load the document and other assets specified in the manifest file from the application cache (not from the server). In addition, the browser also sends a checking event to the window.applicationCache object, and fetches the manifest file, following the appropriate HTTP caching rules.
  4. -
  5. If the currently-cached copy of the manifest is up-to-date, the browser sends a noupdate event to the applicationCache object, and the update process is complete. Note that if you change any cached resources on the server, you must also change the manifest file itself, so that the browser knows it needs to fetch all the resources again.
  6. -
  7. If the manifest file has changed, all the files listed 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 this temporary cache, the browser sends a progress event to the applicationCache object. If any errors occur, the browser sends an error event, and the update halts.
  8. -
  9. Once all the files have been successfully retrieved, they are moved into the real offline cache automatically, and a cached event is sent to the applicationCache object. Since the document has already been loaded into the browser from the cache, the updated document will not be rendered until the document is reloaded (either manually or programatically).
  10. -
- -

Storage location and clearing the offline cache

- -

In Chrome you can clear the offline cache by selecting "Clear browsing data..." in the preferences or by visiting chrome://appcache-internals/. Safari has a similar "Empty cache" setting in its preferences but a browser restart may also be required.

- -

In Firefox, the offline cache data is stored separately from the Firefox profile—next to the regular disk cache:

- - - -

In Firefox the current status of the offline cache can be inspected on the about:cache page (under the "Offline cache device" heading). The offline cache can be cleared for each site separately using the "Remove..." button in Tools -> Options -> Advanced -> Network -> Offline data.

- -

Prior to Firefox 11, neither Tools -> Clear Recent History nor Tools -> Options -> Advanced -> Network -> Offline data -> Clear Now cleared the offline cache. This has been fixed.

- -

On Linux, you can find the setting at Edit > Preferences > Advanced > Network > Offline Web Content and User Data

- -

See also clearing the DOM Storage data.

- -

Application caches can also become obsolete. If an application's manifest file is removed from the server, the browser removes all application caches that use that manifest, and sends an "obsoleted" event to the applicationCache object. This sets the application cache's state to OBSOLETE.

- -

The cache manifest file

- -

Referencing a cache manifest file

- -

The manifest attribute in a web application can specify either the relative path of a cache manifest file or an absolute URL. (Absolute URLs must be from the same origin as the application). A cache manifest file can have any file extension, but it must be served with the MIME type text/cache-manifest.

- -
Note: On Apache servers, the MIME type for manifest (.appcache) files can be set by adding AddType text/cache-manifest .appcache to a .htaccess file within either the root directory, or the same directory as the application.
- -

Entries in a cache manifest file

- -

The cache manifest file is a simple text file that lists the resources the browser should cache for offline access. Resources are identified by URI. Entries listed in the cache manifest must have the same scheme, host, and port as the manifest.

- -

Example 1: a simple cache manifest file

- -

The following is a simple cache manifest file, example.appcache, for an imaginary web site at www.example.com.

- -
CACHE MANIFEST
-# v1 - 2011-08-13
-# This is a comment.
-http://www.example.com/index.html
-http://www.example.com/header.png
-http://www.example.com/blah/blah
-
- -

A cache manifest file can include three sections (CACHE, NETWORK, and FALLBACK, discussed below). In the example above, there is no section header, so all data lines are assumed to be in the explicit (CACHE) section, meaning that the browser should cache all the listed resources in the application cache. Resources can be specified using either absolute or relative URLs (e.g., index.html).

- -

The "v1" comment in the example above is there for a good reason. Browsers only update an application cache when the manifest file changes, byte for byte. If you change a cached resource (for example, you update the header.png image with new content), you must also change the content of the manifest file in order to let browsers know that they need to refresh the cache. You can make any change you want to the manifest file, but revising a version number is the recommended best practice.

- -
Important: Do not specify the manifest itself in the cache manifest file, otherwise it will be nearly impossible to inform the browser a new manifest is available.
- -

Sections in a cache manifest file: CACHE, NETWORK, and FALLBACK

- -

A manifest can have three distinct sections: CACHE, NETWORK, and FALLBACK.

- -
-
CACHE:
-
This is the default section for entries in a cache manifest file. Files listed under the CACHE: section header (or immediately after the CACHE MANIFEST line) are explicitly cached after they're downloaded for the first time.
-
NETWORK:
-
Files listed under the NETWORK: section header in the cache manifest file are white-listed resources that require a connection to the server. All requests to such resources bypass the cache, even if the user is offline. Wildcards may be used.
-
FALLBACK:
-
The FALLBACK: section specifies fallback pages the browser should use if a resource is inaccessible. Each entry in this section lists two URIs—the first is the resource, the second is the fallback. Both URIs must be relative and from the same origin as the manifest file. Wildcards may be used.
-
- -

The CACHE, NETWORK, and FALLBACK sections can be listed in any order in a cache manifest file, and each section can appear more than once in a single manifest.

- -

Example 2: a more complete cache manifest file

- -

The following is a more complete cache manifest file for the imaginary web site at www.example.com:

- -
CACHE MANIFEST
-# v1 2011-08-14
-# This is another comment
-index.html
-cache.html
-style.css
-image1.png
-
-# Use from network if available
-NETWORK:
-network.html
-
-# Fallback content
-FALLBACK:
-/ fallback.html
-
- -

This example uses NETWORK and FALLBACK sections to specify that the network.html page must always be retrieved from the network, and that the fallback.html page should be served as a fallback resource (e.g., in case a connection to the server cannot be established).

- -

Structure of a cache manifest file

- -

Cache manifest files must be served with the text/cache-manifest MIME type. All resources served using this MIME type must follow the syntax for an application cache manifest, as defined in this section.

- -

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 is 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 (after the initial CACHE MANIFEST line), and cannot be appended to other lines. This means that you cannot specify fragment identifiers.
-
Section header
-
Section headers specify which section of the cache manifest is being manipulated. There are three possible section headers:
-
- -
- - - - - - - - - - - - - - - - - - - -
Section headerDescription
CACHE:Switches to the explicit section of the cache manifest (this is the default section).
NETWORK:Switches to the online whitelist section of the cache manifest.
FALLBACK:Switches to the fallback section of the cache manifest.
-
- -
-
The section header line may include whitespaces, but must include the colon (:) in the section name.
-
Section data
-
The format for lines of data varies from section to section. In the explicit (CACHE:) section, each line is a valid URI or IRI reference to a resource to cache (no wildcard characters are allowed in this sections). Whitespace is allowed before and after the URI or IRI on each line. In the Fallback section each line is a valid URI or IRI reference to a resource, followed by a fallback resource that is to be served up when a connection with the server cannot be made. In the network section, each line is a valid URI or IRI reference to a resource to fetch from the network (the wildcard character * is allowed in this section). -
Note: Relative URIs are relative to the cache manifest's URI, not to the URI of the document referencing the manifest.
-
-
- -

Cache manifest files can switch from section to section at will (each section header can be used more than once), and sections are allowed to be empty.

- -

Resources in an application cache

- -

An application cache always includes at least one resource, identified by URI. All resources fit into one of the following categories:

- -
-
Master entries
-
These are resources added to the cache because a browsing context visited by the user included a document that indicated that it was in this cache using its manifest attribute.
-
Explicit entries
-
These are resources explicitly listed in the application's cache manifest file.
-
Network entries
-
These are resources listed in the application's cache manifest files as network entries.
-
Fallback entries
-
These are resources listed in the application's cache manifest files as fallback entries.
-
- -
Note: Resources can be tagged with multiple categories, and can therefore be categorized as multiple entries. For example, an entry can be both an explicit entry and a fallback entry.
- -

Resource categories are described in greater detail below.

- -

Master entries

- -

Master entries are any HTML files that include a {{htmlattrxref("manifest","html")}} attribute in their {{HTMLElement("html")}} element. For example, let's say we have the HTML file http://www.example.com/entry.html, which looks like this:

- -
<html manifest="example.appcache">
-  <h1>Application Cache Example</h1>
-</html>
-
- -

If entry.html is not listed in the example.appcache cache manifest file, visiting the entry.html page causes entry.html to be added to the application cache as a master entry.

- -

Explicit entries

- -

Explicit entries are resources that are explicitly listed in the CACHE section of a cache manifest file.

- -

Network entries

- -

The NETWORK section of a cache manifest file specifies resources for which a web application requires online access. Network entries in an application cache are essentially an "online whitelist"—URIs specified in the NETWORK section are loaded from the server instead of the cache. This lets the browser's security model protect the user from potential security breaches by limiting access to approved resources.

- -

As an example, you can use network entries to load and execute scripts and other code from the server instead of the cache:

- -
CACHE MANIFEST
-NETWORK:
-/api
-
- -

The cache manifest section listed above ensures that requests to load resources contained in the http://www.example.com/api/ subtree always go to the network without attempting to access the cache.

- -
Note: Simply omitting master entries (files that have the manifest attribute set in the html element) from the manifest file would not have the same result, because master entries will be added—and subsequently served from—the application cache.
- -

Fallback entries

- -

Fallback entries are used when an attempt to load a resource fails. For example, let's say the cache manifest file http://www.example.com/example.appcache includes the following content:

- -
CACHE MANIFEST
-FALLBACK:
-example/bar/ example.html
-
- -

Any request to http://www.example.com/example/bar/ or any of its subdirectories and their content cause the browser to issue a network request to attempt to load the requested resource. If the attempt fails, due to either a network failure or a server error of some kind, the browser loads the file example.html instead.

- -

Cache states

- -

Each application cache has a state, which indicates the current condition of the cache. Caches that share the same manifest URI share the same cache state, which can be one of the following:

- -
-
UNCACHED
-
A special value that indicates that an application cache object is not fully initialized.
-
IDLE
-
The application cache is not currently in the process of being updated.
-
CHECKING
-
The manifest is being fetched and checked for updates.
-
DOWNLOADING
-
Resources are being downloaded to be added to the cache, due to a changed resource manifest.
-
UPDATEREADY
-
There is a new version of the application cache available. There is a corresponding updateready event, which is fired instead of the cached event when a new update has been downloaded but not yet activated using the swapCache() method.
-
OBSOLETE
-
The application cache group is now obsolete.
-
- -

Testing for updates to the cache manifest

- -

You can programmatically test to see if an application has an updated cache manifest file, using JavaScript. Since a cache manifest file may have been updated before a script attaches event listeners to test for updates, scripts should always test window.applicationCache.status.

- -
function onUpdateReady() {
-  alert('found new version!');
-}
-window.applicationCache.addEventListener('updateready', onUpdateReady);
-if(window.applicationCache.status === window.applicationCache.UPDATEREADY) {
-  onUpdateReady();
-}
- -

To manually start testing for a new manifest file, you can use window.applicationCache.update().

- -

Gotchas

- - - -

브라우저 호환성

- - - -

{{Compat("html.elements.html.manifest")}}

- -

더 알아보기

- - -- cgit v1.2.3-54-g00ecf