ASP.MVC + AngularJS

时间:2017-06-22 12:16:04

标签: angularjs asp.net-mvc

我有一个ASP.NET MVC和AngularJS的应用程序。 我的路线由AngularJS管理ui-router

AngularJS第一次加载部分视图时它比第二次更慢。是什么导致这个?

有我的代码:

AngularJS

app.config(function ($httpProvider, $urlRouterProvider, $locationProvider, $stateProvider) {
    $urlRouterProvider.otherwise('/home');
    $httpProvider.defaults.headers.common['X-Requested-With'] = 'XMLHttpRequest';
    $locationProvider.html5Mode(true);

    var homeState = {
        name: 'home',
        url:'/home',
        controller: 'HomeCtrl',
        controllerAs:'vm',
        templateUrl:'/AngularJS/Home/Home'   //AngularJS is a Area/Controler/Method
    }
    var loginState = {
        name: 'login',
        url: '/login',
        controller: 'LoginCtrl',
        controllerAs: 'vm',
        templateUrl: '/AngularJS/Home/Login'
    }
    var registrationState = {
        name: 'registration',
        url: '/registration',
        controller: 'RegistrationCtrl',
        controllerAs: 'vm',
        templateUrl: '/AngularJS/Home/Registration'
    }
    var dashboardState = {
        name: 'dashboard',
        url: '/dashboard',
        controller: 'DashboardCtrl',
        controllerAs: 'vm',
        templateUrl: '/AngularJS/Home/Dashboard'
    }

... 
    $stateProvider.state(homeState);
    $stateProvider.state(loginState);
    $stateProvider.state(registrationState);
    $stateProvider.state(dashboardState);
    $stateProvider.state(gameState);
    $stateProvider.state(userState);
    $stateProvider.state(newGameState);
    $stateProvider.state(platformState);
    $stateProvider.state(unavailabilityState);
    $stateProvider.state(teamsState);
    $stateProvider.state(newTeamState);
    $stateProvider.state(editTeamState);
    $stateProvider.state(detailTeamState);

    $httpProvider.interceptors.push(requestInterceptor);


})

ASP.NET MVC

public PartialViewResult Home()
        {
            ViewBag.Title = "Home";
            return PartialView();
        }
        public PartialViewResult Login()
        {
            ViewBag.Title = "Login";
           return PartialView();
        }
        public PartialViewResult Registration()
        {
            ViewBag.Title = "Registration";
            return PartialView();
        }

        public PartialViewResult Dashboard()
        {
            ViewBag.Title = "Dashboard";
            return PartialView();
        }

...

加载时间: 第一 enter image description here

enter image description here

1 个答案:

答案 0 :(得分:0)

应用程序可能正在尝试加载您已添加到模板的大型资源,其中一种方法是使用Chrome浏览器(也可在其他浏览器中使用),请按照以下步骤操作,

右键单击页面转到Inspect元素,然后选择Network tab如下所示。 enter image description here

在那里你可以看到加载每个资源所花费的时间,当它越来越高时,网站将需要更多的时间来加载