understanding jQuery $.getScript()

后端 未结 5 1560
情歌与酒
情歌与酒 2020-12-28 09:39

I use getScript to load dynamically my plugin:

$.getScript(\'js/code.photoswipe.jquery-3.0.4.min.js\', function () {
   //do magic
});
5条回答
  •  自闭症患者
    2020-12-28 10:33

    The jQuery docs for $.getScript say that getScript is shorthand for:

    $.ajax({
      url: url,
      dataType: "script",
      success: success
    });
    

    http://api.jquery.com/jQuery.getScript/

    This means that you just need to add a cache : true parameter to that.

    $.ajax({
      url: url,
      cache : true,
      dataType: "script",
      success: success
    });
    

    Simple as that. The getScript function is nothing special, just shorthand.

提交回复
热议问题