CDNを使用したライブラリの追加(axios)


CDN:コンテンツ配信ネットワーク:コンテンツ転送ネットワーク
プラットフォーム
  • は、サーバとユーザとの物理的距離を低減することにより、Webページコンテンツのロード遅延を最小限に抑える密集したサーバで構成されている
    CDNは、地域によって異なることを避けるために、キャッシュされたバージョンのWebサイトのコンテンツを、「ポイント・ツー・ポイント」と呼ばれる世界中のキャッシュに格納します.
    これらのPoPには、独自のキャッシュ・サーバが含まれており、場所にコンテンツを提供します.
    Webブラウザを実行すると、HTML、CSS、Javascript、画像ファイルの表示に必要なコンテンツが要求されます.
    ほとんどのCDNでは、コンテンツに対して各リクエストが発行されると、エンドユーザーは最適な配置のCDNサーバにマッピングされ、サーバはリクエストファイルのキャッシュ(プリ保存)バージョンに応答します.
    Webサイト上のコンテンツ転送はCDNで最も一般的な方法ですが、異なるタイプのコンテンツも転送されます.
  • 4 kやハイビジョンビデオなど
  • すべてのデジタル化可能なデータはCDNを介して
  • を伝送することができる.
    unpkg cdn, jsDelivery
  • npmに登録されているサービスパッケージは、直接CDNとして使用できます.
    axiosの使用例
    
    // Make a request for a user with a given ID
    axios.get('/user?ID=12345')
      .then(function (response) {
        // handle success
        console.log(response);
      })
      .catch(function (error) {
        // handle error
        console.log(error);
      })
      .then(function () {
        // always executed
      });
    
    // Optionally the request above could also be done as
    axios.get('/user', {
        params: {
          ID: 12345
        }
      })
      .then(function (response) {
        console.log(response);
      })
      .catch(function (error) {
        console.log(error);
      })
      .then(function () {
        // always executed
      });  
    
    // Want to use async/await? Add the `async` keyword to your outer function/method.
    async function getUser() {
      try {
        const response = await axios.get('/user?ID=12345');
        console.log(response);
      } catch (error) {
        console.error(error);
      }
    }
    
    // GET
    const getUsers = () => {
    axios.get('https://reqres.in/api/users')
    .then(response => {
    const users = response.data.data;
    console.log(`GET users`, users);
    })
     .catch(error => console.error(error));
    };
    getUsers();
    
    // POST
    const createUser = (user) => {
    axios.post('https://reqres.in/api/users', user)
    .then(response => {
    const addedUser = response.data;
    console.log(`POST: user is added`, addedUser);
    // append to DOM
     appendToDOM([addedUser]);
     })
     .catch(error => console.error(error));
    };
    
    // DELETE
    const deleteUser = (elem, id) => {
    axios.delete(`https://reqres.in/api/users/${id}`)
    .then(response => {
    console.log(`DELETE: user is removed`, id);
    // remove elem from DOM
    elem.remove();
    })
    .catch(error => console.error(error));
    };
    参考文献
  • https://www.akamai.com/kr/ko/cdn/what-is-a-cdn.jsp
  • https://github.com/axios/axios
  • https://ichi.pro/ko/vanilla-javascripteseo-axiosleul-sayonghaneun-bangbeob-50298755090644