Polymer website takes 5 seconds to load - javascript

My little Polymer 1.0 Starter Kit app takes 5 seconds to load. The site also uses Page.js.
I am following this tutorial on how to speed up your polymer app. But I'm on the video section.
I've used loadCSS in my app and the set up:
<head>
<script src="scripts/loadCSS.js"></script>
<script src="scripts/onloadCSS.js"></script>
<!-- build:js bower_components/webcomponentsjs/webcomponents-lite.min.js -->
<script src="bower_components/webcomponentsjs/webcomponents-lite.js"></script>
<!-- endbuild -->
<!-- will be replaced with elements/elements.vulcanized.html -->
<link rel="import" href="elements/elements.html">
<!-- endreplace-->
</head>
<body>
<span id="browser-sync-binding"></span>
<template is="dom-bind" id="app">
<paper-header-panel main mode="waterfall">
<paper-toolbar>
//web links etc
</paper-toolbar>
// Main Content
<div class="content" style="display:none">
<script>
onloadCSS(loadCSS('styles/main.css'), function() {
document.querySelector('.content')
.style.display = ''; // should show the content after css is loaded?
});
</script>
<noscript><link rel="stylesheet" href="/styles/main.css"></noscript>
<noscript><link rel="stylesheet" href="/styles/skeleton.css"></noscript>
<iron-pages attr-for-selected="data-route" selected="{{route}}">
// all the elements ie: <my-app></my-app>
</iron-papes>
</div>
</paper-header-panel>
</template>
</body>
Only the <paper-toolbar> loads and nothing else. Why .style.display = ''; does not work?
Thanks

Related

Angular not working in app launch

I've working in Cordova app with Angularjs and all looks fine in Chrome and other browsers. But if I try install the apk to Android, Angularjs not execute the index.html in the launch.
However, that's is the weirdest: if I change for other pages and go back to the index.html, all looks fine! And if I close the app and relaunch, everything goes to normal. And sometimes, just in few times, it repeats, only in the index.html.
My index.html when launch:
enter image description here
Just as I said, the pages works fine in the most cases:
enter image description here
I'm using Android 7.1.1 / Cordova 7.0.1 / Angular 1.6.4
index.html: (Each 'ng-init' inside 'ng-owl-carousel' makes a $http request)
<!DOCTYPE html>
<html ng-app="baseApp">
<head>
<link rel="stylesheet" href="css/uikit.css" />
<link rel="stylesheet" href="css/header.css" />
<link rel="stylesheet" href="css/custom.css" />
<link rel="stylesheet" href="css/owl.carousel.min.css">
<link rel="stylesheet" href="css/animate.css" />
<script src="js/jquery.js"></script>
<script src="js/uikit.min.js"></script>
<script src="js/owl.carousel.js"></script>
<script src="js/angular.min.js"></script>
<script src="js/angular-owl-carousel-2.js"></script>
<script src="js/index.js"></script>
<script src="js/controller-home.js"></script>
<script src="js/controller-list.js"></script>
<script src="js/controller-rede.js"></script>
<script src="js/controller-config.js"></script>
</head>
<body ng-controller="carousel" ng-cloak>
<header ng-include="'templates/header-search.html'"></header>
<section>
<ng-owl-carousel class="owl-theme" owl-items="items" owl-properties="properties" owl-ready="ready($api)">
<div ng-controller="home">
<div ng-include="'templates/home.html'" ng-show="owl_page == 0" ng-init="init_home();"></div>
</div>
<div ng-controller="listas">
<div ng-include="'templates/listas.html'" ng-show="owl_page == 1" ng-init="init_listas();"></div>
</div>
<div ng-controller="rede">
<div ng-include="'templates/rede.html'" ng-show="owl_page == 2" ng-init="generalSearchFilter('notify');"></div>
</div>
<div ng-controller="config">
<div ng-include="'templates/config.html'" ng-show="owl_page == 3" ng-init="init_config();"></div>
</div>
</ng-owl-carousel>
</section>
<footer id="footer" ng-include="'templates/footer.html'"></footer>
<script src="cordova.js"></script>
</body>
</html>
After some days I decided to change all my index.html and I change my code to use $routeProvider instead ng-include, also I replace my initial function with a 'angular.element(document).ready' + $timeout. Happy end! :)

Angular use ng-include to include a template that include others

i'm trying in my app to include a template (already shown) that include other template.
index.html
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Tasks Overview</title>
<!-- Angular framework -->
<script src="assets/js/angular.min.js"></script>
<!-- Main module -->
<script src="app.js"></script>
<!-- Components -->
<!-- Services -->
<script src="app/components/logger/logger-service.js"></script>
<script src="app/components/resource/resource-service.js"></script>
<script src="app/components/integrity_check/integrity_check-service.js"></script>
<script src="app/components/date_utilities/month_translation_utility-service.js"></script>
<!-- History -->
<script src="app/components/history/history-controller.js"></script>
<!-- Period -->
<script src="app/components/period/period-controller.js"></script>
<script src="app/components/period/directives/year_picker/year_picker-directive.js"></script>
<script src="app/components/period/directives/month_picker/month_picker-directive.js"></script>
<!-- Shell -->
<script src="app/components/shell/shell-controller.js"></script>
<!-- Calendar -->
<script src="app/components/calendar/directives/day/day-directive.js"></script>
<script src="app/components/calendar/calendar-controller.js"></script>
<!-- UI libraries -->
<link rel="stylesheet" type="text/css" href="assets/css/materialize.min.css">
<link rel="stylesheet" type="text/css" href="assets/css/system.css">
<script src="assets/js/jquery-3.1.0.min.js"></script>
<script src="assets/js/materialize.min.js"></script>
<!-- Task entities -->
<script src="app/components/task/task-controller.js"></script>
<script src="app/components/task/tasks-service.js"></script>
<!-- Main -->
<script src="app/components/main/main-controller.js"></script>
<!-- Google material icons -->
<link href="https://fonts.googleapis.com/icon?family=Material+Icons"
rel="stylesheet">
<!-- External libraries -->
<script src="assets/js/FileSystem.js"></script>
</head>
<body ng-app="wtd">
<!--History component-->
<div id="history" ng-include="'app/components/history/history_main-view.html'" ng-controller="historyController as vm"></div>
<!--Period component-->
<div id="period" ng-include="'app/components/period/period_main-view.html'" ng-controller="periodController as vm"></div>
<!--Calendar component-->
<div id="calendar" ng-include="'app/components/calendar/calendar_main-view.html'" ng-controller="calendarController as vm"></div>
<!--Shell component-->
<div id="shell" ng-include="'app/components/shell/shell_main-view.html'" ng-controller="shellController as vm"></div>
<!--Main controller-->
<div id="main" ng-controller="mainController"></div>
</body>
</html>
calendar_main-view.html
<div class="col l10 offset-l1 m10 offset-m1 s10 offset-s1">
<!-- List view mode -->
<div ng-if="view.mode.list" ng-include="app/components/calendar/calendar_list-view.html">
</div>
<!-- Grid view mode -->
<div ng-if="view.mode.grid" ng-include="app/components/calendar/calendar_grid-view.html"></div>
</div>
Problem appear on the second level of ng-include (file calendar_grid-view.html). No one xhr call is done by browser to include the file.
What's wrong?
You are missing single quote.
<div ng-if="view.mode.list" ng-include="'app/components/calendar/calendar_list-view.html'">
<div ng-if="view.mode.grid" ng-include="'app/components/calendar/calendar_grid-view.html'"></div>
Make sure view.mode.list and view.mode.grid evaluted to truthy in order to display html.

How to get this code working in angular with wowslider.js?

I've tried many times to run this code but every time it appears incorrectly I want angular to make its affect like this demo:
http://wowslider.com/angular-slider-collage-demo.html.
Please help, I've tried too many times without the intended result.
<!DOCTYPE html>
<html ng-app="myapp">
<head>
<title>Http://wowslider.net/</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<meta name="description" content="Made with WOW Slider - Create beautiful, responsive image sliders in a few clicks. Awesome skins and animations. Http://wowslider.net/" />
<!-- Start WOWSlider.com HEAD section --> <!-- add to the <head> of your page -->
<link rel="stylesheet" type="text/css" href="engine1/style.css" />
<script type="text/javascript" src="engine1/jquery.js"></script>
<!-- End WOWSlider.com HEAD section -->
</head>
<body style="background-color:#d7d7d7;margin:0" >
<!-- Start WOWSlider.com BODY section --> <!-- add to the <body> of your page -->
<div id="wowslider-container1" >
<div class="ws_images" ng-controller="HelloController">
<ul>
<li ng-repeat="img in allimages"><img ng-src="data1/images/{{img.name}}" alt="2016-chevrolet-cruze-spied-completely-uncovered-news-car-and-driver-photo-658949-s-217x132" title="2016-chevrolet-cruze-spied-completely-uncovered-news-car-and-driver-photo-658949-s-217x132" id="wows1_0"/></li>
</ul>
</div>
<div class="ws_bullets">
<div>
<a ng-repeat="img in allimages" href="#" title="2016-chevrolet-cruze-spied-completely-uncovered-news-car-and-driver-photo-658949-s-217x132"><span><img ng-src="data1/tooltips/{{img.name}}" alt="2016-chevrolet-cruze-spied-completely-uncovered-news-car-and-driver-photo-658949-s-217x132"/>1</span></a>
</div>
</div>
<div class="ws_script" style="position:absolute;left:-99%">http://wowslider.net/ by WOWSlider.com v8.7</div>
<div class="ws_shadow"></div>
</div>
<!-- End WOWSlider.com BODY section -->
<script type="text/javascript" src="engine1/angular.js"></script>
<script>
angular.module("myapp", [])
.controller("HelloController", function($scope) {
$scope.allimages = [{name:'2016chevroletcruzespiedcompletelyuncoverednewscaranddriverphoto658949s217x132.jpg'},{name:'2016chrysler300srtspieditsalivenewscaranddriverphoto658864s217x132.jpg'}];
});
</script>
<script type="text/javascript" src="engine1/wowslider.js"></script>
<script type="text/javascript" src="engine1/script.js"></script>
</body>
</html>

jQuery mobile doesn't trigger pageshow code between pages

I am writing a jQuery mobile app that contains two HTML pages. When user navigates from index.html page to search.html page, jQuery should load elements into search.html page.
However, things seems to gone wrong. The script doesn't work as expected.
index.html
<!DOCTYPE html>
<head>
<!-- Include meta tag to ensure proper rendering and touch zooming -->
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta charset="utf-8">
<!-- Include jQuery Mobile stylesheets -->
<link rel="stylesheet" href="css/jquery.mobile-1.4.5.min.css" ></link>
<link rel="stylesheet" href="css/mahidol.min.css"></link>
<link rel="stylesheet" href="css/themes/jquery.mobile.icons.min.css"></link>
<!-- Include the jQuery library -->
<script src="js/jquery-1.11.3.min.js"></script>
<!-- Include the jQuery Mobile library -->
<script src="js/jquery.mobile-1.4.5.min.js"></script>
<!-- Cordova sh*ts -->
<script type="text/javascript" src="cordova.js"></script>
<script src="js/parameterHandler.js"></script>
<script src="js/default.js"></script>
</head>
<body>
<div data-role="page" id="index">
<div data-role="header" data-position="fixed">
Preferences
<h1><img src="logo.png" height="15px"> Contact</h1>
</div>
<div data-role="main" class="ui-content">
<form class="ui-filterable">
Search from name
<input id="filterBoxList" data-type="search" placeholder="Type here to search from department list">
</form>
<ul data-role="listview" data-filter="true" data-input="#filterBoxList" id="list_dept">
</ul>
</div>
</div>
</body>
search.html
<!DOCTYPE html>
<head>
<!-- Include meta tag to ensure proper rendering and touch zooming -->
<meta name="viewport" content="width=device-width, initial-scale=1"></meta>
<meta charset="utf-8"></meta>
<!-- Include jQuery Mobile stylesheets -->
<link rel="stylesheet" href="css/jquery.mobile-1.4.5.min.css" ></link>
<link rel="stylesheet" href="css/mahidol.min.css"></link>
<link rel="stylesheet" href="css/themes/jquery.mobile.icons.min.css"></link>
<!-- Include the jQuery library -->
<script src="js/jquery-1.11.3.min.js"></script>
<!-- Include the jQuery Mobile library -->
<script src="js/jquery.mobile-1.4.5.min.js"></script>
<!-- Cordova shits -->
<script type="text/javascript" src="cordova.js"></script>
<script src="js/parameterHandler.js"></script>
<script src="js/default.js"></script>
<style>
#listie small{
color: #ccc !important;
}
</style>
</head>
<body>
<div data-role="page" id="search">
<div data-role="header" data-position="fixed">
Preferences
<h1><img src="logo.png" height="15px"> Contact</h1>
</div>
<div data-role="main" class="ui-content">
<form class="ui-filterable">
Search from dept. list
<input id="filterBoxName" data-type="search" placeholder="Type here to search from name">
</form>
<ul data-role="listview" data-filter="true" data-input="#filterBoxName" id="listie">
</ul>
</div>
</div>
</body>
default.js (loaded the last)
$(document).on("pageshow","search.html",function(){
var chx = 0;
var m="";
var k=[];
$.mobile.loading( "show", {
text: 'Loading',
textVisible: true
});
if(loaded == false) // This will prevent event triggering more then once
{
for (var t in JSON.parse(localStorage.getItem('hr')))
{
m += "<li><a href='#view?id=" + t + "'>" + JSON.parse(localStorage.getItem('hr'))[t].Name + " <small>" + JSON.parse(localStorage.getItem('hr'))[t].Surname + "</small></a></li>";
}
$('#listie').append(m).listview('refresh');
loaded = true;
}
$.mobile.loading( "hide" );
});
Things seems to be nice when the "search" page div is placed inside index.html (and the code is linked in single page, not two). However it does break when I tried splitting up the files into two files.
Anything I can do to fix this?
Well, solved...
Even though the div is on the same file, when using $(document).on("pageshow",src,function(){...}); to point to src, makes sure that src points to the div ID, not the file itself.
In this case, it's $(document).on("pageshow","#search",function(){...});.

Javascript Loading Order – Prevent Page Jumpiness

See how this page loads its content for a while, then triggers the javascript after some delay? http://nomoresnoring.com/new/
How can I make things load more smoothly? Should anything be reordered?
Header:
<head>
<script src="_/js/modernizr.custom.min.js"></script><!-- modernizr -->
<script src="//code.jquery.com/jquery-latest.min.js"></script><!-- jquery -->
<script src="_/js/jquery.leanModal.min.js"></script><!-- leanModal -->
<script src="_/js/jquery.sticky.min.js"></script><!-- sticky -->
<script src="_/js/jquery.customSelect.min.js"></script><!-- customSelect -->
<script src="_/js/jquery.scrollUp.min.js"></script><!-- scrollUp -->
<script src="_/js/happy.js"></script><!-- happy.js -->
<script src="_/js/happy.methods.js"></script><!-- happy.js -->
<!-- some other things -->
<script src="_/js/rhinoslider-1.05.min.js"></script><!-- rhinoslider -->
</head>
Footer:
<script type="text/javascript" src="_/js/functions.js"></script><!-- all custom functions -->
<script src="_/js/rhinoslider-1.05.min.js"></script><!-- for Rhinoslider -->
<script src="_/js/mousewheel.js"></script><!-- for Rhinoslider -->
<script src="_/js/easing.js"></script><!-- for Rhinoslider -->
</body>
</html>
You can do:
//just before closing head tag
<style>body{display:none}</style>
</head>
//just before closing body tag
window.onload = function(){
$('body').fadeIn();
};
</body>
You could use a preloader animation too.

Categories