Single-Page Application

Junghoo Cho

cho@cs.ucla.edu

Single-Page Application (SPA)

SPA Example

Fetch API

Coding Google Suggest (1)

Coding Google Suggest (2)

More on Fetch API: Cutomizing Request

More on Fetch API: Error Handling

Same-Origin Policy

Cross-Origin Resource Sharing (CORS)

CORS HTTP Headers

How to Use CORS

XML

XML: Google Suggest Example

<?xml version="1.0"?>
<toplevel>
    <CompleteSuggestion>
        <suggestion data="ucla"/>
    </CompleteSuggestion>
    <CompleteSuggestion>
        <suggestion data="ucla basketball"/>
    </CompleteSuggestion>
    ...
</toplevel>

XML String ⇆ XML DOM

Handling Google Suggest Response (1)

Handling Google Suggest Response (2)

Back Button

Deep Link

Pre-HTML5: URL Fragment Identifier

location.hash and onhashchange

HTML5: Session History API

Web Storage API (1)

Web Storage API (2)

    // store data
    localStorage["username"] = "John";
    localStorage["object"] = JSON.stringify(obj);

    // get data
    let name = localStorage["username"];
    // iterate over all stored keys
    for(let key in localStorage) { 
        let value = localStorage[key];
    }

    // remove data
    localStorage.removeItem("username"); 
    localStorage.clear();  // delete everything

Web Storage API (3)

IndexedDB

What We Learned

References