LoginSignup
0
0

More than 1 year has passed since last update.

ブラウザが対応しているかどうかは必ず確認しておく
ちなみに
*chrome
*Edge
*Safari
以上3つは使えるとのこと

dinamic importの目的

ページの初期表示時の処理負荷をへらす
(必要な時に必要なだけ使う)
→コンテンツが展開する度に必要なモジュールを遅延ロードする方法

比較

今までの静的メソッド

→ページがインポートされた時点で、モジュールもインポートされる

import{ publicVal,publicFn} from './moduleA.js';

publicFn();

動的メソッド

→モジュールは必要な時だけ、非同期によって呼ばれる

//書き方1. 
import('./moduleA.js').then(function(modules){
	console.log(modules);
  modules.publicFn();
})
//書き方2.
async function fn(){
    const modules = await import('./moduleA.js');
    modules.publlicFn();
}) 

1.モジュール自体をインポートする関数を作成する
2.インスタンスに落とし込み、関数を実行する

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0