Angularjs app doesn't render well on slow internet connection - angularjs

I got excited over the prospects of AngularJS. So I started learning it right away. However, to my dismay, AngularJS doesn't render content well on slow internet connections as you can see from the screenshots.
My Flask App basically displays my Linux machines details. I do this by running an ajax call to the server-side code and return json which I then display to the browser using Angular.
Is this a known problem with the framework or is it the way am writing my code. I call Angularjs at the footer as rendered by many users.
Here's a skeleton structure of my html page
<!DOCTYPE html>
<html >
<head>
<title>My flask app</title>
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="{{ url_for('static', filename='css/bootstrap.min.css') }}">
<link rel="stylesheet" href="{{ url_for('static', filename='css/bootstrap-glyphicons.css') }}">
<!-- font awesome -->
<link rel="stylesheet" href="{{ url_for('static', filename='css/font-awesome.min.css') }}">
<!-- custom-->
<link rel="stylesheet" href="{{ url_for('static', filename='css/main.css') }}">
</head>
<body ng-app="flaskApp">
<header>
<div class="container">
<h1 class="logo">Flask App</h1>
<strong><nav>
<ul class="menu">
<li>Home</li>
<li>About</li>
</ul>
</nav></strong>
</div>
</header>
<div class="container">
{% block content %}
{% endblock %}
</div>
<!-- Jquery JS-->
<script src="{{ url_for('static', filename='js/jquery-1.11.3.min.js')}}"></script>
<!-- Angular JS-->
<script src="{{ url_for('static', filename='js/angular.js')}}"></script>
<!-- Bootstrap JS -->
<script src="{{ url_for('static', filename='js/bootstrap.min.js')}}"></script>
<!-- Custom JS -->
<!-- <script src="{{ url_for('static', filename='js/admin.js')}}"></script> -->
<script src="{{ url_for('static', filename='js/cmd.js')}}"></script>
</body>
</html>

Take a look at ngClock directive. It is used to prevent Angular from displaying uncompiled templates.
Add this to your CSS file:
[ng\:cloak], [ng-cloak], [data-ng-cloak], [x-ng-cloak], .ng-cloak, .x-ng-cloak {
display: none !important;
}
and include de ng-cloak directive where you want. I usually put it in the body tag.

Related

Change class of the menu on scroll in angular + bootstrap

I am new to angular and I am simply trying to switch between two bootstrap defined menu classes on scroll. What I am trying to achieve is that the menu stays fixed to the top with changed background (as provided in bootstrap css) when scroll is not on top of the page. I have tried using ng-class, but nothing is happening. The google chrome inspector doesn't report any errors. Here is what I have so far:
html:
<html lang="en" ng-app = "cvApp">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="">
<meta name="author" content="">
<title>CV creation</title>
<!-- Bootstrap Core CSS -->
<link href="assets/bootstrap/css/bootstrap.min.css" rel="stylesheet">
<!-- Theme CSS -->
<link href="assets/bootstrap/css/clean-blog.min.css" rel="stylesheet">
<!-- Custom Fonts -->
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Bitter:400,700">
<!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
<script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<body style="background-color:#FF0000;">
<div>
<nav class = "navbar navbar-default navbar-custom navbar-fixed-top"
ng-class="{'navbar navbar-default navbar-custom navbar-fixed-top is-fixed is-visible':boolChangeClass}">
<div class="container-fluid">
<!-- Brand and toggle get grouped for better mobile display -->
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1" >
<ul class="nav navbar-nav navbar-right">
<li>
Save
</li>
<li>
Export
</li>
</ul>
</div>
<!-- /.navbar-collapse -->
</div>
<!-- /.container -->
</nav>
</div>
<div>
<br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
<br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br></div>
<script src="js/angular.min.js?q=123"></script>
<script src="js/angular-route.min.js?q=123"></script>
<script src="app/cvapp.js?q=123"></script>
<script src="app/Controllers/MenuController.js?q=123"></script>
</body>
</html>
module "cvApp" with directive:
var cvApp = angular.module('cvApp', []);
cvApp.directive("scroll", function ($window) {
return function(scope, element, attrs) {
angular.element($window).bind("scroll", function() {
if (this.pageYOffset >= 0) {
scope.boolChangeClass = true;
} else {
scope.boolChangeClass = false;
}
scope.$apply();
});
};
});
I would like some insight on what I am doing wrong and thank you in advance.
In the code that you have provided, i can not see you using the directive in the markup anywhere.
change your markup to :
<nav scroll class = "navbar navbar-default navbar-custom navbar-fixed-top"
ng-class="{'navbar navbar-default navbar-custom navbar-fixed-top is-fixed is-visible':boolChangeClass}"> ...
and it would work.
Here is a basic fiddle for example (doesn't include bootstrap, but you can see that the class is being applied on scroll, the background of nav changes from red to green):
http://jsfiddle.net/Lvc0u55v/13347/

AngularJS - Does Routing Harm SEO?

I am sure there are techniques to have a better SEO approach using AngularJS features, (https://prerender.io/js-seo/angularjs-seo-get-your-site-indexed-and-to-the-top-of-the-search-results/).
As an example, the source code of a project I am currently developing, returns the next:
<html lang="en" data-ng-app="ByTheWayApp" data-ng-controller="general">
<head>
<title>ByTheWay</title>
<base href="/" />
<meta charset="utf-8" />
<!-- Fonts -->
<link href="https://fonts.googleapis.com/css?family=Comfortaa:300,400,700|Courgette|Open+Sans:300,300i,400,400i,600,600i,700,700i,800,800i&subset=cyrillic,cyrillic-ext,greek,latin-ext" rel="stylesheet">
<link
rel="stylesheet"
type="text/css"
href="/assets/css/bytheway.css">
<link
rel="stylesheet"
type="text/css"
ng-href="{{ templateCSS }}">
</head>
<body>
<app>
<div class="loading">
<span>ByTheWay</span>
</div>
<div class="app-wrapper {{ displayClass }}" load >
<header class="header h-3 fixed">
<div class="inner-wrapper">
<div class="brand wpx-7">
<a href="/">
<h1 class="title"><span>ByTheWay</span></h1>
<h2 class="slogan"><span>chasing dreams worldwide</span></h2>
</a>
</div>
<nav class="nav w-auto text-right aw-const" id="nav">
home
sign in
<strong>sign up</strong>
</nav>
</div>
</header>
<div class="page" data-ng-controller="page" data-ng-view>
<!-- Here Go Every Page Templates using $routeProvider.when('',{}); -->
</div>
</div>
</app>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.5.8/angular.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.5.8/angular-route.js"></script>
<script type="text/javascript" src="/assets/js/bytheway.js"></script>
</body>
</html>
.
<div class="page"></div> would contain the Template .html file content, but it is not displayed when I check the source code, does the same happen when Google Spiders/Bots crawl my site ?
ps. I am not using yet meta tags, such description, tags, etc, because I am yet defining relevant content to be displayed.
Thank you and all the best

angularjs django integration

I can load the page with items if I include the angularjs declaration inside script tag in index.html. Otherwise, not working.
app/templates/app/index.html
{% load staticfiles %}
<html>
<head>
<link rel="stylesheet" type="text/css" href="{% static "components/bootstrap/dist/css/bootstrap.css" %}">
<script type="text/javascript" src="{% static "javascript/app.js"%}"></script>
<script type="text/javascript" src="{% static "components/angular/angular.min.js"%}"></script>
<script type="text/javascript" src="{% static "components/angular-route/angular-route.js"%}"></script>
</head>
<body ng-app="store">
<div ng-controller="ItemController">
{% verbatim %}
<div class="panel" ng-repeat="item in items">
<p>{{ item.id }}</p>
</div>
{% endverbatim %}
</div>
</body>
</html>
app/static/javascript/app.js
angular.module('store', ['ngRoute'])
.controller('ItemController', function($scope, $http) {
$http.get('/api/items').success(function(data){
$scope.items = data;
});
});
After installing the angular plugin on chrome, when I load the page, it shows me this error. "Module was created but never loaded". After playing for a while, I figure it is because I load my app.js before I load angular.js.

ionic content not scrolling

I have gone through many answers, but nothing worked for me. I have a simple .html file and ionic content just does not scroll.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width">
<title></title>
<link href="lib/ionic/css/ionic.css" rel="stylesheet">
<link href="css/style.css" rel="stylesheet">
<!-- IF using Sass (run gulp sass first), then uncomment below and remove the CSS includes above
<link href="css/ionic.app.css" rel="stylesheet">
-->
<script src="js/platformOverrides.js"></script>
<script src="scripts/angular-resource.min.js"></script>
<!-- ionic/angularjs js -->
<script src="lib/ionic/js/ionic.bundle.js"></script>
<!-- cordova script (this will be a 404 during development) -->
<script src="cordova.js"></script>
<script src="scripts/jquery.min.js"></script>
<script src="scripts/angular-sanitize.min.js"></script>
<script src="scripts/angular-ui-router.js"></script>
<script src="scripts/angular-resource.js"></script>
<script src="scripts/lodash.min.js"></script>
<script src="js/app.js"></script>
<script src="js/appController.js"></script>
</head>
<body ng-app="app" ng-controller="appController">
<ion-pane>
<ion-header-bar class="bar-stable">
<h1 class="title">Ionic Blank Starter</h1>
</ion-header-bar>
<ion-view>
<ion-content scroll="true">
<div class="scroll">
<a ng-repeat="item in items" class="item" href="#">
<h2>{{item.name}}</h2>
</a>
</div>
</ion-content>
</ion-view>
</ion-pane>
</body>
</html>
Above, $scope.items is being fetched from some webservice. Everything renders fine but it just does not scroll.
I am using Visual studio 'Ionic Blank Template' if that matters. I have configured Cordova correctly and rest all solutions just work fine.
Remove the class="scroll" from the div container, scroll="true" from ion-content and add overflow-scroll="true" . The required classes will be added by ionic on the elements. You don't need to add that explicitly
<ion-view>
<ion-content overflow-scroll="true">
<div class="list">
<a ng-repeat="item in items" class="item" href="#">
<h2>{{item.name}}</h2>
</a>
</div>
</ion-content>
</ion-view>
Update: The codepen showing the scrollable list in chrome simulator: http://codepen.io/addi90/full/RaOegM/
In ionic v1.3.3 or later, scroll on is not working. this can be solved by placing overflow-scroll="false" in or defining as
<ion-content overflow-scroll="false">
OR
<ion-scroll scrollX="true" scrollY="true" style="margin:17rem; position:fixed; display:inline; top:0; right:0; bottom:0; left:0; white-space: nowrap;">
will help.
Sandy to hide the scrollbar try to add ::-webkit-scrollbar {display:none;} to your css file. It worked for me.

Why CakePHP Bootstrap files in 'app/webroot' is not loaded from add.ctp file?

In my CakePHP project I've put all my css and js files in 'app/webroot' folder and index.ctp is loaded with all designs. But add.ctp and edit.ctp files are load without css/js files in '../webroot'.
$this->layout = 'newlayout';
I put this code in my andex(), add() and edit() action in 'controller' file.
My newlayout.ctp file code is
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title><?php echo $title_for_layout; ?></title>
<!-- Tell the browser to be responsive to screen width -->
<meta content='width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no' name='viewport'>
<!-- Bootstrap 3.3.4 -->
<link href="bootstrap/css/bootstrap.min.css" rel="stylesheet" type="text/css" />
<!-- FontAwesome 4.3.0 -->
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css" rel="stylesheet" type="text/css" />
<!-- Ionicons 2.0.0 -->
<link href="https://code.ionicframework.com/ionicons/2.0.1/css/ionicons.min.css" rel="stylesheet" type="text/css" />
<!-- Theme style -->
<link href="dist/css/AdminLTE.min.css" rel="stylesheet" type="text/css" />
<!-- AdminLTE Skins. Choose a skin from the css/skins
folder instead of downloading all of them to reduce the load. -->
<link href="dist/css/skins/_all-skins.min.css" rel="stylesheet" type="text/css" />
<!-- iCheck -->
<link href="plugins/iCheck/flat/blue.css" rel="stylesheet" type="text/css" />
<!-- Morris chart -->
<link href="plugins/morris/morris.css" rel="stylesheet" type="text/css" />
<!-- jvectormap -->
<link href="plugins/jvectormap/jquery-jvectormap-1.2.2.css" rel="stylesheet" type="text/css" />
<!-- Date Picker -->
<link href="plugins/datepicker/datepicker3.css" rel="stylesheet" type="text/css" />
<!-- Daterange picker -->
<link href="plugins/daterangepicker/daterangepicker-bs3.css" rel="stylesheet" type="text/css" />
<!-- bootstrap wysihtml5 - text editor -->
<link href="plugins/bootstrap-wysihtml5/bootstrap3-wysihtml5.min.css" rel="stylesheet" type="text/css" />
<!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<body class="skin-blue sidebar-mini">
<div class="wrapper">
<header class="main-header">
<!-- Logo -->
<a href="#" class="logo">
<!-- mini logo for sidebar mini 50x50 pixels -->
<!-- logo for regular state and mobile devices -->
<span class="logo-lg"><b>POS</b> App</span>
</a>
<!-- Header Navbar: style can be found in header.less -->
<nav class="navbar navbar-static-top" role="navigation">
<!-- Sidebar toggle button-->
<a href="#" class="sidebar-toggle" data-toggle="offcanvas" role="button">
<span class="sr-only">Toggle navigation</span>
</a>
<div class="navbar-custom-menu">
<ul class="nav navbar-nav">
<!-- Messages: style can be found in dropdown.less-->
<!-- Notifications: style can be found in dropdown.less -->
<!-- Tasks: style can be found in dropdown.less -->
<!-- User Account: style can be found in dropdown.less -->
<!-- Control Sidebar Toggle Button -->
</ul>
</div>
</nav>
</header>
<!-- Left side column. contains the logo and sidebar -->
<aside class="main-sidebar">
<!-- sidebar: style can be found in sidebar.less -->
<section class="sidebar">
<!-- Sidebar user panel -->
<div class="user-panel">
</div>
<!-- sidebar menu: : style can be found in sidebar.less -->
</section>
<!-- /.sidebar -->
</aside>
<!-- Content Wrapper. Contains page content -->
<div class="content-wrapper">
<!-- Content Header (Page header) -->
<section class="content-header">
<h1>
<?php echo $this->Session->flash(); ?>
</h1>
<ol class="breadcrumb">
<li><i class="fa fa-dashboard"></i> Home</li>
<li class="active">Dashboard</li>
</ol>
</section>
<!-- Main content -->
<section class="content">
<?php echo $this->fetch('content'); ?>
</section><!-- /.content -->
</div><!-- /.content-wrapper -->
<footer class="main-footer">
<strong>Copyright © 2014-2015 .</strong> All rights reserved.
</footer>
<!-- Control Sidebar -->
<div class='control-sidebar-bg'></div>
</div><!-- ./wrapper -->
<!-- jQuery 2.1.4 -->
<script src="plugins/jQuery/jQuery-2.1.4.min.js"></script>
<!-- jQuery UI 1.11.4 -->
<script src="https://code.jquery.com/ui/1.11.4/jquery-ui.min.js" type="text/javascript"></script>
<!-- Resolve conflict in jQuery UI tooltip with Bootstrap tooltip -->
<script>
$.widget.bridge('uibutton', $.ui.button);
</script>
<!-- Bootstrap 3.3.2 JS -->
<script src="bootstrap/js/bootstrap.min.js" type="text/javascript"></script>
<!-- Morris.js charts -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/raphael/2.1.0/raphael-min.js"></script>
<script src="plugins/morris/morris.min.js" type="text/javascript"></script>
<!-- Sparkline -->
<script src="plugins/sparkline/jquery.sparkline.min.js" type="text/javascript"></script>
<!-- jvectormap -->
<script src="plugins/jvectormap/jquery-jvectormap-1.2.2.min.js" type="text/javascript"></script>
<script src="plugins/jvectormap/jquery-jvectormap-world-mill-en.js" type="text/javascript"></script>
<!-- jQuery Knob Chart -->
<script src="plugins/knob/jquery.knob.js" type="text/javascript"></script>
<!-- daterangepicker -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.10.2/moment.min.js" type="text/javascript"></script>
<script src="plugins/daterangepicker/daterangepicker.js" type="text/javascript"></script>
<!-- datepicker -->
<script src="plugins/datepicker/bootstrap-datepicker.js" type="text/javascript"></script>
<!-- Bootstrap WYSIHTML5 -->
<script src="plugins/bootstrap-wysihtml5/bootstrap3-wysihtml5.all.min.js" type="text/javascript"></script>
<!-- Slimscroll -->
<script src="plugins/slimScroll/jquery.slimscroll.min.js" type="text/javascript"></script>
<!-- FastClick -->
<script src='plugins/fastclick/fastclick.min.js'></script>
<!-- AdminLTE App -->
<script src="dist/js/app.min.js" type="text/javascript"></script>
<!-- AdminLTE dashboard demo (This is only for demo purposes) -->
<script src="dist/js/pages/dashboard.js" type="text/javascript"></script>
<!-- AdminLTE for demo purposes -->
<script src="dist/js/demo.js" type="text/javascript"></script>
</body>
</html>
I've checked the request response for 'add' pageload and i got this response -
The action bootstrap is not defined in controller
and each request for css and js file got this kind of error response!
I've no clue!
You should use CakePHP Helper to include assets file(css, js etc). Let's see how to use include css files?
<head>
<?php echo $this->Html->css(array('forms', 'tables', 'menu')); ?>
// forms, tables, menu are the css file thoese are locate under app/webroot/css directory
</head>
Look HtmlHelper::css on CakePHP 2.x
The error you have described,
The action bootstrap is not defined in controller
...is telling you that the action/route you are attempting to load, bootstrap(), is not a function found in that controller.
The above issue is likely unrelated to loading bootstrap. Double-check the route/URL you are attempting to access. If it is http://example.com/controller/bootstrap then the function (action) bootstrap() must be defined in that controller.
Once that is dealt with, you can find a working example of using Twitter Bootstrap with CakePHP in the source of this app on GitHub, which powers stats.chrisvogt.me.
In this example I am using a hosted version of Bootstrap, but in the line below it you'll find an extension called Jasny Bootstrap that is located in ./app/webroot/components/jasny-bootstrap/[...]jasny-bootstrap.min.css.
Also, in case you don't want to repeatedly define $this->layout in each of those actions: you can define a default custom layout for all actions using beforeFilter() in the AppController like so, or you can do this in individual controllers if you wish.
While not required, I'm a fan of using Bower to manage my front-end components (such as Bootstrap). Should you feel like looking into this, make sure to define a custom install directory somewhere under ./webroot.

Resources