2017-02-10 56 views
0

正在使用requiredjs。部署到任何環境(現在的本地截圖)之後,會出現刷新問題。頁面加載不正確。我檢查了螢火蟲的網絡標籤。其顯示(下圖)。當文件得到200 OK(BF Cache)狀態時,頁面加載不正常。從瀏覽器緩存中訪問文件時需要JS Refress Issue

enter image description here

錯誤:

enter image description here

給Ctrl + F5

完所有頁面來了正常。

​​

一段時間,我需要給很多CTRL + F5的則只有其工作asexpected

我requirejs配置文件:

require.config({ 
    baseUrl: "../../../../../../../Scripts", 
    //waitSecond: 0, 
    //urlArgs : "q="+new Date().getTime(), 
    enforcedefine: true, 
    paths: { 
     //RequireJS Plugins. 
     'text': 'lib/requirejs/text', 
     'domReady': 'lib/requirejs/domReady', 
     'app': 'app', 
     'noext': 'lib/requirejs/noext', 

     // Shared Libraries. 
     'jquery': 'lib/Kendo/jquery.min', 
     'jqueryMigrate': 'lib/jquery-migrate-1.2.1.min', 
     'jszip': 'lib/jszip', 
     'kendo': 'lib/Kendo/kendo.all.min', 
     'materialize': 'lib/materialize/materialize', 
     'jqueryValidate': 'jquery.validate.min', 
     'jsignature': 'lib/jSignature/jSignature.min', 
     'jqueryMaskedinput': 'lib/jquery/jquery.maskedinput.min', 
     'jqueryMd5': 'lib/jquery/jquery.md5', 
     'truckNotifier': 'Controls/serviceTruck.Notifier' 
    }, 
    shim: { 
     'app': { 
      deps: ['kendo'] 
     }, 
     'kendo': { 
      deps: ['jquery', 'jszip'], 
     }, 
     'jqueryExtensions': { 
      deps: ['jquery'], 
     }, 
     'materialize': { 
      deps: ['jquery', 'kendo'], 
     }, 
     'krossRespJs': { 
      deps: ['jquery'], 
     }, 
     'jqueryMaskedinput': { 
      deps: ['jquery'], 
     }, 
     'truckUploadSelector': { 
      deps: ['jquery'], 
     }, 
     'underscore': { 
      exports: '_' 
     } 
    } 
}); 

app.js文件:

(function (factory) { 
    if (typeof define === 'function' && define.amd) { 
     // AMD. Register as an anonymous module. 
     define([ 
      'domReady!', 
      'text', 
      'noext', 
      'jquery', 
      'kendo', 
      'jszip', 
      'truckNotifier' 
     ], factory); 
    } else { 
     // Browser globals 
     factory(jQuery); 
    } 
}(function (domReady,text,noext,$,kendo,jszip,truckNotifier) { 
    'use strict'; 
    var app = kendo.observable({ 
     // ---- PUBLIC FIELDS ---- 
     DATE_FORMAT: 'MM/dd/yyyy', 
     DATE_MASK: '99/99/9999', 
     DATE_TIME_FORMAT: 'MM/dd/yyyy HH:mm', 
     DATE_TIME_MASK: '99/99/9999 99:99', 
     PHONE_MASK: '(999) 999-9999', 
     TIME_FORMAT: 'HH:mm', 
     TIME_MASK: '99:99', 
     $notifier: $('#notify_container'), 
     router: new kendo.Router(), 
     isInitialized: false, 
     /** This call sets up background components of the current page. */ 

     initialize: function() { 
      var self = this; 
      // Initialize this first so it can show loading while the rest 
      // of this module loads. 

      if (!self.isInitialized) { 
       $('.link-external').attr('target', '_blank'); 

       $('#notify_container').serviceTruckNotifier(); 
       self.isInitialized = true; 
      } 

      window.JSZip = jszip; 

     }, 
     showPleaseWait: function (show) { 
     }, 
     /* Pops up a notification at the top of the page. */ 
     notify: function (type, message) { 
      var types = { 
       'push': 'notifyPush', 
       'info': 'notifyInfo', 
       'success': 'notifySuccess', 
       'error': 'notifyError', 
       'warn': 'notifyWarn', 
       'expired': 'notifyExpired' 
      }; 
      this.$notifier.serviceTruckNotifier(types[type], message); 
     } 
    }); 
    app.initialize(); 
    return app; 
})); 
在查看頁面中使用

腳本:

<script> 
    require([ 
     'domReady!', 
     'text', 
     'noext', 
     'app', 
     'jquery', 
     'jqueryValidate', 
     'kendo', 
     'truckNotifier' 
    ], 
    function (
     domReady, 
     text, 
     noext, 
     app, 
     $, 
     jqueryValidate, 
     kendo, 
     truckNotifier 
     ) { 
     var notifier = $('#notify_container'), 
      message = '@(ViewBag.Message)'; 
     $("#primaryTextButton").kendoButton(); 
     $('.all-content').removeClass('dn'); 
     $('.mcenter').addClass('dn'); 
     if (message != "") { 
      notifier.serviceTruckNotifier("notifyExpired", "@C.LINK_HAS_BEEN_EXPIRED"); 
     } 
    }); 
</script> 

HTML文件:

<!DOCTYPE html> 
<html lang="en"> 
<head> 
    <meta charset="utf-8" /> 
    <title>@ViewBag.Title</title> 
    <link href="~/favicon.ico" rel="shortcut icon" type="image/x-icon" /> 
    <meta name="viewport" content="width=device-width" /> 
    @Styles.Render("~/Content/Styles/all/css") 
    <script src="~/Scripts/lib/requirejs/require.js"></script> 
    <script src="~/Scripts/config.js"></script> 

</head> 
<body id="@RenderSection("BodyId", false)"> 
    @{ 
     System.Reflection.Assembly web = typeof(ServiceTruck.Web.Models.ExternalLogin).Assembly; 

     System.Reflection.Assembly assembly = System.Reflection.Assembly.GetExecutingAssembly(); 
     System.Diagnostics.FileVersionInfo fvi = System.Diagnostics.FileVersionInfo.GetVersionInfo(web.Location); 
     string version = fvi.FileVersion; 

     System.Reflection.AssemblyName webName = web.GetName(); 
     string myVersion = version.ToString(); 
     ViewBag.Version = myVersion; 
    } 

    @RenderSection("featured", required: false) 
    <section class="container-fluid"> 
     @RenderBody() 
    </section> 
    <!-- Service Truck Layout Footer Start --> 
    <footer class="copy-right"> 
     <div class="col-md-6 text-left"> 
      <p>All rights reserved.</p> 
      <p>Copyright © 2016 <a href="#">Name</a>.</p> 
     </div> 
     <div class="col-md-6 text-right"> 
      <p>Build @myVersion</p> 
      <p>Recommended Browsers: Internet Explorer 11, Firefox 48, Chrome 52</p> 
     </div> 
    </footer> 
    <!-- Service Truck Layout Footer End --> 
    @RenderSection("scripts", required: false) 

</body> 
</html> 
+0

間歇性錯誤大部分時間是由於錯誤地配置RequireJS或由不良的啓動順序造成的。現在你的問題沒有包含足夠的信息來允許猜測什麼是錯誤的。請編輯你的問題到[mcve]。特別是,您需要顯示您的RequireJS配置以及如何啓動代碼加載('script'標記的順序與HTML中相同)。 – Louis

+0

我已經更新了這個問題,你可以請檢查一下。 –

+0

一個代碼片段的標題爲「文件」。好的,但是這是什麼文件?您正在加載大量文件。此外,我之前的評論說:「你需要展示如何啓動代碼加載**(腳本標籤的順序與HTML中的相同)**」。 (強調添加。)您沒有按照與HTML相同的順序顯示'script'標籤。這很重要。這是開始你的應用程序的一部分。 – Louis

回答

0

有一點是肯定錯了你的配置是shimapp

'app': { 
     deps: ['kendo'] 
    }, 

您的app模塊是AMD模塊:它稱爲define。所以你不能使用shim。設置shim對於無法從中受益的模塊可能會導致未定義的行爲。

我已經對此進行過實驗並且從RequireJS的一個版本得到了不一致的結果。關鍵是爲AMD模塊設置shim沒有定義的語義。

+0

我已經刪除了'app'的依賴關係。仍然面臨同樣的問題 –