0

HTMLとjavascript/ajaxで構成されるプロジェクトをセットアップしようとしています-多くのjqueryプラグインを備えたjquery。

多くのHTMLページのそれぞれについて、RequireJSを使用する必要があり、ここに私が望むものがあります..

縮小されたファイルまたは縮小されていないファイルをロードする必要があるプロパティ (ajax 呼び出しからの戻り値) に基づいて決定したい

そのため、(ページの読み込み前またはページの読み込みが開始されるとすぐに) どの js ファイルを読み込みたいかを判断して決定し、読み込みを進めるメカニズムが必要です。

これを行う良い方法はありますか?

4

1 に答える 1

1

良い、

この例を見てください:

html

<!DOCTYPE html>
<html>
    <head>
        <title>My Sample Project</title>
        <!-- data-main attribute tells require.js to load
             scripts/main.js after require.js loads. -->
        <script data-main="scripts/main" src="scripts/require.js"></script>
    </head>
    <body>
        <h1>My Sample Project</h1>
    </body>
</html>

scripts / main.js

$.ajax({
  url: "http://server.com/fetchMeSomeData"
  context: document.body,
  success: function(data){
    //this would be your sample callback
    // you could be fetching the parameter to ask if it is debug state or not.
    var isDebugSuffix = (data.isDebug)? "" : ".min";

    require(["helper/util" + isDebugSuffix], function() {
        //This function is called when scripts/helper/util.min.js is loaded but when the 
        //isDebug would be True, it would load scripts/helper/utils.js

        //your other code can go here ...    
    });

  }
});

これがあなたの道にあなたを設定することを願っています...

于 2011-09-14T17:00:55.623 に答える