amiletti / spapp

Simple single page jquery application library
8 stars 4 forks source link

Feature Request: Add js and css into routing #1

Open RacerDelux opened 5 years ago

RacerDelux commented 5 years ago

Currently your documentation only shows the ability to load specific html. I have added a fix to let me include js as well, but it would be better IMO to have the routing take care of this. For reference, here is the function I use for loading js files:

function loadScript(name) {
          let scripts = Array
              .from(document.querySelectorAll('script'))
              .map(scr => scr.src);

          if (!scripts.includes(name)) {
              var tag = document.createElement('script');
              tag.src = name;
              document.getElementsByTagName('body')[0].appendChild(tag);
          }
      }

This will prevent any script from being loaded more than once as well.