How to preload large css and javascript files in vanilla javascript

Tags: javascript,css,preload

Problem :

I'm building a single page application that's going to run on tablets in areas of the world that have slow connections with poor bandwidth.

Because the javascript files and css files are quite big, the css file is 250kb and the main js file is 750kb at the moment, I'm looking for a best practice to preload the css and javascript files without having to first load libraries such as JQuery first.

So in short: What is a good way to preload css and js files without 3rd party libraries and have some sort of callback once all the files are loaded

Solution :

[...] having to first load libraries such as JQuery first.

What you want to achieve can be done without libraries or frameworks (actually they still use vanilla JS under the hoods), anyway, science moves on when everyone don't try to re-invent the wheel every day.

There're simple but yet powerful libraries that have a very small footprint that are just there to asynchronously-loading JavaScript and CSS files that work like a charm.

For example, HeadJS is a 1.9KB library and it can solve your issue:

head.load("myfile1.js", "myfile2.js", "mystyles.css", function() {
   // Do stuff once they got loaded!

    CSS Howto..

    How to change color of the selected item from a Xul listbox?

    CSS HTML - How to add more outer colour on the drop down menus and more than one word per drop down

    How to debug the different behavior of the same browser on the different platforms?

    How do I vertically center text and have the dark blue bar go across the entire screen

    How to vertically center text span in fixed position div?

    How to CSS the select field so that it occupy the entire cell of my table?

    How to translate html, css and js into one javascript (animation)

    CSS - How can I make a font readable over any color?

    CSS horizontal scroller, how to position “below” before “right”?

    How To Fix This “Select” Drop Down Using Css [duplicate]

    How to make text-overflow with ellipsis work with long strings that have no breaks

    How to hide child element entirely if it is cut off by it's parent's overflow:hidden property?

    how can I position my img right?

    How to make round corners to both inside of a box and its border?

    How to make a responsive mosaic css fullscreen width

    How can I archive this responsive design?

    How to hide DIV when scroll reach at Bottom through CSS?

    How to preload predefined images in Java-Script / jQuery?

    Background image cut off outside of item. How can I make it show?

    How much client-side programming is needed when doing server-side programming?

    how to apply conditional stylesheet $this->headLink()->appendStylesheet('css/css.css') with zend-framework

    How can I see “:hover” and “:active” properties of elements on a webpage? [duplicate]

    How to zoom in / out depending on browser height, using CSS zoom property? [closed]

    How to add inset box-shadow to mapbox-div?

    How to remove table column with CSS

    How to style a particular paragraph element in css without effecting the other paragraphs in the same class?

    jQuery slideshow image delay

    how to add class to razor form and give padding?

    How to prevent transition to run on page load after height is set with javascript in Safari?

    how is Zurb's Foundation Menu button coded?