반응형

OFFLINE & STORAGE

 

[스토리지] web-storage-demo-gh-pages

 

로컬 스토리지를 이용한 예제

 

web-storage-demo

A simple demo to show usage of the Web Storage API. For more detail on how it works, read Using the Web Storage API.

View the demo online: http://mdn.github.io/web-storage-demo/

 

 

A simple demo to show usage of the Web Storage API. For more detail on how it works, read https://developer.mozilla.org/en-US/docs/Web/API/Web_Storage_API/Using_the_Web_Storage_API

 

 

반응형
반응형

네이티브앱을 만들기만 하던 시대를 지나 이젠 웹으로 앱을 만드는게 보편화 되어버린 시대로 도달했다.

하이브리드앱은 이미 많은 검증을 거쳤고, 상용화되서 시장을 점유하고 있는것이 사실이다.

대표적인 앱제작플롯폼으로 "폰갭(http://phonegap.com/)"을 들 수 있다.

폰갭,앱스프레소, 티타늄들 많이 있지만, 폰갭이 가장 간단하고 사용하기 좋은거 같다. 


자바스크립트를 이용한 처리가 작년만 해도 느렸지만, 하드웨어 성능도 향상되고, 자바스크립트 엔진 성능도 향상되어 지금은 네이티브 API를 사용하는것을 거의 따라잡았다고 볼 수 있다.

오프라인에서는 HTML5 캐시 또는 Web Storage 기능등이 있기때문에 온라인이 아니더라도 일반적인 정보를 보여줄 수 있게되었다. (Web Storage, Web SQL DB, IndexedDB ) 캐시 기능은 문제가 캐시가 잘 변경이 되지 않는다는 단점이 있긴 하지만. 오프라인에서도 화면을 잘 보여준다. 서버 셋팅만 잘 해두었다면 말이다.


HTML5 application Cache

What is Application Cache?

HTML5 introduces application cache, which means that a web application is cached, and accessible without an internet connection.

Application cache gives an application three advantages:

  1. Offline browsing - users can use the application when they're offline
  2. Speed - cached resources load faster
  3. Reduced server load - the browser will only download updated/changed resources from the server

Browser Support

Internet Explorer Firefox Opera Google Chrome Safari

Application cache is supported in all major browsers, except Internet Explorer.


* 일단 서버에서 manifest 타입이 웹에서 활성화 되어야 한다.

   contentType = "text/cache-manifest" 이 적용되어야 한다.

   (contentType만 맞추면 jsp 파일로 구현가능하다. )


1. manifest 파일에 애플리케이션 캐시정책이 기록되어 있다.

    - 어떤 파일을 캐시할지, 오프라인에서 어떤 파일을 보여줄 것인지 등등

2. 처음 화면 접속시 manifest 파일의 내용을 캐시를 해둔다. 

3.두번째 부터는 manifest 파일이 갱신되지 않았으면 캐시를 불러온다.

4.갱신이 되어있어도 일단 캐시를 불러오고, 백그라운드로 업데이트를 한다.

   그래서, 갱신해도 처음에는 이전 캐시를 보여주고 새로고침을 한번 더하거나 하면 갱신된 내용을 보여준다.


웹이 발전하는것은 결국 사용자 편의성을 위한 것이지, 어떤 특정한 기술로 인해 편의성을 져버린다면 그 서비스는 퇴화될것이다 .







반응형
반응형

Having fun with HTML5 — Local Storage and Session Storage


API

The full API spec­i­fi­ca­tion for the local­Stor­age and ses­sion­Stor­age objects can be found here. At the time of writ­ing, this is how the com­mon Stor­age inter­face look:

image

Demo

I’ve put together a quick demo here to illus­trate how to detect and use the local and ses­sion stor­age to get, set, remove and clear stored items (well, basi­cally, cov­ers each of the avail­able meth­ods on the Stor­age inter­face above).

The page itself is sim­ple and crude, just a cou­ple of <div> and most impor­tantly two tables which I use to show all the key value pairs stored in the local and ses­sion storage:

image

Intro­duc­ing the new place­holder attribute

You might have noticed that the two text boxes had place­holder text sim­i­lar to that famil­iar search box in Firefox:

text boxes with place holder text Firefox search box

This is done using HTML5’s place­holder attribute for the <input> tag:

1
2
<input id="keyText" placeholder="Enter key"/>
<input id="valueText" placeholder="Enter value"/>

Nice and easy, eh? ;-)

Set­ting an item

To add a new key value pair or update the value asso­ci­ated with an exist­ing key, you just have to call the setItem method on the intended stor­age object:

1
2
3
4
5
6
7
8
9
10
11
12
13
// adds a new key to both local and session storage
function setKey() {
var key = $("#keyText").val();
var value = $("#valueText").val();
if (Modernizr.localstorage) {
localStorage.setItem(key, value);
}
if (Modernizr.sessionstorage) {
sessionStorage.setItem(key, value);
}
showKeys();
}
Remov­ing an item

Ear­lier in the showStorageKeys(type, table) func­tion, I added a row to the rel­e­vant table for each key value pair in the stor­age includ­ing a but­ton with a han­dler for the onclick event. The han­dlers are cre­ated with the cor­rect stor­age type (“local” or “ses­sion”) and key for the cur­rent row baked in already so that they will call the removeItem(type, key) func­tion with the cor­rect parameters:

1
2
3
4
5
6
7
// removes an item with the specified key from the specified type of storage
function removeItem(type, key) {
// get the specified type of storage, i.e. local or session
var storage = window[type + 'Storage'];
storage.removeItem(key);
showKeys();
}
Clear­ing all items

Finally, the ’”Clear” but­tons under­neath the tables call the clear­LocalKeys() and clearS­es­sion­Keys() func­tion to remove all the key value pairs in the cor­re­spond­ing storage:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
function clearLocalKeys() {
clearKeys("local");
}
function clearSessionKeys() {
clearKeys("session");
}
// clear all the held keys in the specified type of storage
function clearKeys(type) {
// get the specified type of storage, i.e. local or session
var storage = window[type + 'Storage'];
// clear the keys
storage.clear();
showKeys();
}


반응형

+ Recent posts