(function(module) {
  // Object constructor function
  /*
    the data we are getting is coming from the function:

        projectsList.forEach(function(project) {
          projects.push(new Projects(project));
        });

    for each is looping through
    Key = the key in the projectsList object
  */
  function Projects (projectsList) {
    for (key in projectsList) {
      this[key] = projectsList[key];
    }
  }

  // Function to get the project template from index.html and then compile and render the template.
  Projects.prototype.toHtml = function () {
    var source = $('#project_template').html();
    var templateRender = Handlebars.compile(source);
    return templateRender(this);
  };

  Projects.loadAll = function (inputProjects) {
    // Function to sort the projectsList array of objects by date.
    Projects.allProjects = inputProjects.sort(function (currentProject, nextProject) {
      return (new Date(nextProject.projectDate)) - (new Date(currentProject.projectDate));
    })
    .map(function(ele) {
      // Push each constrcutred object from the projectsList into the projects array.
      return new Projects(ele);
    });
  };

  Projects.fetchAll = function () {
    if (localStorage.projects) {
      var projects = JSON.parse(localStorage.getItem('projects'));
      Projects.loadAll(projects);
      Projects.allProjects.map(function(project){
        $('#projects').append(project.toHtml());
      });
      console.log('Loaded from Local');
    } else {
      $.getJSON('../data/projectsData.json', function (projects) {
        Projects.loadAll(projects);
        localStorage.setItem('projects', JSON.stringify(projects));
        Projects.allProjects.map(function(project){
          $('#projects').append(project.toHtml());
        });
        console.log('Loaded from database');
      });
    }
  };

  Handlebars.registerHelper('list', function (skills, options) {
    var ulEl = '<ul class="skills">';
    for (var i = 0, j = skills.length; i < j; i++) {
      ulEl = ulEl + '<li>' + options.fn(skills[i]) + '</li>';
    }
    return ulEl + '</ul>';
  });

  Projects.fetchAll();
  module.Projects = Projects;

})(window);

@@ -50,263 +50,8 @@
 ion%0A
-  /*%0A    the data we are getting is coming from the function:%0A%0A        projectsList.forEach(function(project) %7B%0A          projects.push(new Projects(project));%0A        %7D);%0A%0A    for each is looping through%0A    Key = the key in the projectsList object%0A  */%0A
   fu
@@ -499,75 +499,8 @@
 ) %7B%0A
-    // Function to sort the projectsList array of objects by date.%0A
     
@@ -709,94 +709,8 @@
 ) %7B%0A
-      // Push each constrcutred object from the projectsList into the projects array.%0A
     
@@ -762,24 +762,28 @@
 rojects.
-fetchAll
+loadDatabase
  = funct
@@ -799,33 +799,79 @@
     
-if (localStorage.projects
+$.getJSON('../data/projectsData.json', function (projects, message, xhr
 ) %7B%0A
@@ -880,34 +880,42 @@
     
-var p
+P
 rojects
- = JSON.parse(
+.loadAll(projects);%0A      
 loca
@@ -923,17 +923,17 @@
 Storage.
-g
+s
 etItem('
@@ -945,34 +945,24 @@
 cts'
-));%0A      Projects.loadAll
+, JSON.stringify
 (pro
@@ -959,32 +959,33 @@
 ingify(projects)
+)
 ;%0A      Projects
@@ -1075,24 +1075,91 @@
 ;%0A      %7D);%0A
+      localStorage.setItem('ETag', xhr.getResponseHeader('ETag'));%0A
       consol
@@ -1181,13 +1181,16 @@
 rom 
-Local
+database
 ');%0A
@@ -1198,127 +1198,319 @@
    %7D
- else %7B%0A      $.getJSON('../data/projectsData.json', function (projects) %7B%0A        Projects.loadAll(projects);%0A        
+);%0A  %7D;%0A%0A  Projects.fetchAll = function () %7B%0A    if (localStorage.projects) %7B%0A      $.ajax(%7B%0A        url: '../data/projectsData.json',%0A        type: 'HEAD',%0A        success: function (data, message, xhr)%7B%0A          if(localStorage.ETag === xhr.getResponseHeader('ETag')) %7B%0A            var projects = JSON.parse(
 loca
@@ -1510,33 +1510,33 @@
 se(localStorage.
-s
+g
 etItem('projects
@@ -1536,32 +1536,48 @@
 rojects'
-, JSON.stringify
+));%0A            Projects.loadAll
 (project
@@ -1574,27 +1574,30 @@
 ll(projects)
-)
 ;%0A
+    
         Proj
@@ -1638,32 +1638,36 @@
 ect)%7B%0A          
+  
+  
 $('#projects').a
@@ -1695,28 +1695,36 @@
 ));%0A        
-%7D);%0A
+    %7D);%0A    
         cons
@@ -1740,33 +1740,86 @@
 Loaded from 
-d
+Local');%0A          %7D else %7B%0A            Projects.loadD
 atabase
-'
+(
 );%0A      %7D);
@@ -1811,25 +1811,91 @@
 se();%0A      
+ 
-%7D
+   %7D%0A        %7D%0A      %7D);%0A    %7D else %7B%0A      Projects.loadDatabase(
 );%0A    %7D%0A  %7D

refactor projects load script to use etag and load from database when detecting new etag