{"id":2666,"date":"2017-09-01T16:28:03","date_gmt":"2017-09-01T16:28:03","guid":{"rendered":"https:\/\/allurewebsolutions.com\/?p=2666"},"modified":"2017-09-01T16:28:03","modified_gmt":"2017-09-01T16:28:03","slug":"easily-preload-images-css-js-javascript","status":"publish","type":"post","link":"https:\/\/allurewebsolutions.com\/easily-preload-images-css-js-javascript","title":{"rendered":"How To Easily Preload Images \/ CSS \/ JS With Javascript"},"content":{"rendered":"<p>With this snippet you can easily preload your images, css, js. The script initiates after the page loaded so it doesn&#8217;t affect loading time.<\/p>\n<pre class=\"prettyprint lang-javascript\" data-start-line=\"1\" data-visibility=\"visible\" data-highlight=\"\" data-caption=\"\">window.onload = function() {\n\n\tsetTimeout(function() {\n\n\t\t\/\/ reference to &lt;head&gt;\n\t\tvar head = document.getElementsByTagName('head')[0];\n\n\t\t\/\/ a new CSS\n\t\tvar css = document.createElement('link');\n\t\tcss.type = \"text\/css\";\n\t\tcss.rel  = \"stylesheet\";\n\t\tcss.href = \"http:\/\/domain.tld\/preload.css\";\n\n\t\t\/\/ a new JS\n\t\tvar js  = document.createElement(\"script\");\n\t\tjs.type = \"text\/javascript\";\n\t\tjs.src  = \"http:\/\/domain.tld\/preload.js\";\n\n\t\t\/\/ preload JS and CSS\n\t\thead.appendChild(css);\n\t\thead.appendChild(js);\n\n\t\t\/\/ preload image\n\t\tnew Image().src = \"http:\/\/domain.tld\/preload.png\";\n\n\t}, 1000);\n\n};\n\n\/\/ Credits: https:\/\/perishablepress.com\/3-ways-preload-images-css-javascript-ajax\/<\/pre>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>With this snippet you can easily preload your images, css, js. The script initiates after the page loaded so it doesn&#8217;t affect loading time. window.onload = function() { setTimeout(function() {&#8230;<\/p>\n","protected":false},"author":9,"featured_media":2227,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2,21],"tags":[],"class_list":{"0":"post-2666","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","7":"category-blog","8":"category-javascript"},"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>How To Easily Preload Images \/ CSS \/ JS With Javascript - Allure Web Solutions<\/title>\n<meta name=\"robots\" content=\"noindex, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How To Easily Preload Images \/ CSS \/ JS With Javascript - Allure Web Solutions\" \/>\n<meta property=\"og:description\" content=\"With this snippet you can easily preload your images, css, js. The script initiates after the page loaded so it doesn&#8217;t affect loading time. window.onload = function() { setTimeout(function() {...\" \/>\n<meta property=\"og:url\" content=\"https:\/\/allurewebsolutions.com\/easily-preload-images-css-js-javascript\" \/>\n<meta property=\"og:site_name\" content=\"Allure Web Solutions\" \/>\n<meta property=\"article:published_time\" content=\"2017-09-01T16:28:03+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/allureprojects.com\/app\/uploads\/sites\/40\/2017\/03\/allure-code-snippet.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"800\" \/>\n\t<meta property=\"og:image:height\" content=\"300\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"allure\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"allure\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/allurewebsolutions.com\\\/easily-preload-images-css-js-javascript#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/allurewebsolutions.com\\\/easily-preload-images-css-js-javascript\"},\"author\":{\"name\":\"allure\",\"@id\":\"https:\\\/\\\/allurewebsolutions.com\\\/#\\\/schema\\\/person\\\/cd83b1da73d5792d2ffbe7240c212e75\"},\"headline\":\"How To Easily Preload Images \\\/ CSS \\\/ JS With Javascript\",\"datePublished\":\"2017-09-01T16:28:03+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/allurewebsolutions.com\\\/easily-preload-images-css-js-javascript\"},\"wordCount\":35,\"commentCount\":0,\"image\":{\"@id\":\"https:\\\/\\\/allurewebsolutions.com\\\/easily-preload-images-css-js-javascript#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/allureprojects.com\\\/app\\\/uploads\\\/sites\\\/40\\\/2017\\\/03\\\/allure-code-snippet.jpg\",\"articleSection\":[\"Blog\",\"Javascript\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/allurewebsolutions.com\\\/easily-preload-images-css-js-javascript#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/allurewebsolutions.com\\\/easily-preload-images-css-js-javascript\",\"url\":\"https:\\\/\\\/allurewebsolutions.com\\\/easily-preload-images-css-js-javascript\",\"name\":\"How To Easily Preload Images \\\/ CSS \\\/ JS With Javascript - Allure Web Solutions\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/allurewebsolutions.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/allurewebsolutions.com\\\/easily-preload-images-css-js-javascript#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/allurewebsolutions.com\\\/easily-preload-images-css-js-javascript#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/allureprojects.com\\\/app\\\/uploads\\\/sites\\\/40\\\/2017\\\/03\\\/allure-code-snippet.jpg\",\"datePublished\":\"2017-09-01T16:28:03+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/allurewebsolutions.com\\\/#\\\/schema\\\/person\\\/cd83b1da73d5792d2ffbe7240c212e75\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/allurewebsolutions.com\\\/easily-preload-images-css-js-javascript#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/allurewebsolutions.com\\\/easily-preload-images-css-js-javascript\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/allurewebsolutions.com\\\/easily-preload-images-css-js-javascript#primaryimage\",\"url\":\"https:\\\/\\\/allureprojects.com\\\/app\\\/uploads\\\/sites\\\/40\\\/2017\\\/03\\\/allure-code-snippet.jpg\",\"contentUrl\":\"https:\\\/\\\/allureprojects.com\\\/app\\\/uploads\\\/sites\\\/40\\\/2017\\\/03\\\/allure-code-snippet.jpg\",\"width\":800,\"height\":300,\"caption\":\"Allure Web Solutions Code Snippet\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/allurewebsolutions.com\\\/easily-preload-images-css-js-javascript#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/allurewebsolutions.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How To Easily Preload Images \\\/ CSS \\\/ JS With Javascript\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/allurewebsolutions.com\\\/#website\",\"url\":\"https:\\\/\\\/allurewebsolutions.com\\\/\",\"name\":\"Allure Web Solutions\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/allurewebsolutions.com\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/allurewebsolutions.com\\\/#\\\/schema\\\/person\\\/cd83b1da73d5792d2ffbe7240c212e75\",\"name\":\"allure\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/5bce3b7ae368a17245089ce9f6aceaa527a31cc28e6d3cd10e417aee15218f0f?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/5bce3b7ae368a17245089ce9f6aceaa527a31cc28e6d3cd10e417aee15218f0f?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/5bce3b7ae368a17245089ce9f6aceaa527a31cc28e6d3cd10e417aee15218f0f?s=96&d=mm&r=g\",\"caption\":\"allure\"},\"url\":\"https:\\\/\\\/allurewebsolutions.com\\\/author\\\/allure\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How To Easily Preload Images \/ CSS \/ JS With Javascript - Allure Web Solutions","robots":{"index":"noindex","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"og_locale":"en_US","og_type":"article","og_title":"How To Easily Preload Images \/ CSS \/ JS With Javascript - Allure Web Solutions","og_description":"With this snippet you can easily preload your images, css, js. The script initiates after the page loaded so it doesn&#8217;t affect loading time. window.onload = function() { setTimeout(function() {...","og_url":"https:\/\/allurewebsolutions.com\/easily-preload-images-css-js-javascript","og_site_name":"Allure Web Solutions","article_published_time":"2017-09-01T16:28:03+00:00","og_image":[{"width":800,"height":300,"url":"https:\/\/allureprojects.com\/app\/uploads\/sites\/40\/2017\/03\/allure-code-snippet.jpg","type":"image\/jpeg"}],"author":"allure","twitter_card":"summary_large_image","twitter_misc":{"Written by":"allure","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/allurewebsolutions.com\/easily-preload-images-css-js-javascript#article","isPartOf":{"@id":"https:\/\/allurewebsolutions.com\/easily-preload-images-css-js-javascript"},"author":{"name":"allure","@id":"https:\/\/allurewebsolutions.com\/#\/schema\/person\/cd83b1da73d5792d2ffbe7240c212e75"},"headline":"How To Easily Preload Images \/ CSS \/ JS With Javascript","datePublished":"2017-09-01T16:28:03+00:00","mainEntityOfPage":{"@id":"https:\/\/allurewebsolutions.com\/easily-preload-images-css-js-javascript"},"wordCount":35,"commentCount":0,"image":{"@id":"https:\/\/allurewebsolutions.com\/easily-preload-images-css-js-javascript#primaryimage"},"thumbnailUrl":"https:\/\/allureprojects.com\/app\/uploads\/sites\/40\/2017\/03\/allure-code-snippet.jpg","articleSection":["Blog","Javascript"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/allurewebsolutions.com\/easily-preload-images-css-js-javascript#respond"]}]},{"@type":"WebPage","@id":"https:\/\/allurewebsolutions.com\/easily-preload-images-css-js-javascript","url":"https:\/\/allurewebsolutions.com\/easily-preload-images-css-js-javascript","name":"How To Easily Preload Images \/ CSS \/ JS With Javascript - Allure Web Solutions","isPartOf":{"@id":"https:\/\/allurewebsolutions.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/allurewebsolutions.com\/easily-preload-images-css-js-javascript#primaryimage"},"image":{"@id":"https:\/\/allurewebsolutions.com\/easily-preload-images-css-js-javascript#primaryimage"},"thumbnailUrl":"https:\/\/allureprojects.com\/app\/uploads\/sites\/40\/2017\/03\/allure-code-snippet.jpg","datePublished":"2017-09-01T16:28:03+00:00","author":{"@id":"https:\/\/allurewebsolutions.com\/#\/schema\/person\/cd83b1da73d5792d2ffbe7240c212e75"},"breadcrumb":{"@id":"https:\/\/allurewebsolutions.com\/easily-preload-images-css-js-javascript#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/allurewebsolutions.com\/easily-preload-images-css-js-javascript"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/allurewebsolutions.com\/easily-preload-images-css-js-javascript#primaryimage","url":"https:\/\/allureprojects.com\/app\/uploads\/sites\/40\/2017\/03\/allure-code-snippet.jpg","contentUrl":"https:\/\/allureprojects.com\/app\/uploads\/sites\/40\/2017\/03\/allure-code-snippet.jpg","width":800,"height":300,"caption":"Allure Web Solutions Code Snippet"},{"@type":"BreadcrumbList","@id":"https:\/\/allurewebsolutions.com\/easily-preload-images-css-js-javascript#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/allurewebsolutions.com\/"},{"@type":"ListItem","position":2,"name":"How To Easily Preload Images \/ CSS \/ JS With Javascript"}]},{"@type":"WebSite","@id":"https:\/\/allurewebsolutions.com\/#website","url":"https:\/\/allurewebsolutions.com\/","name":"Allure Web Solutions","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/allurewebsolutions.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/allurewebsolutions.com\/#\/schema\/person\/cd83b1da73d5792d2ffbe7240c212e75","name":"allure","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/5bce3b7ae368a17245089ce9f6aceaa527a31cc28e6d3cd10e417aee15218f0f?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/5bce3b7ae368a17245089ce9f6aceaa527a31cc28e6d3cd10e417aee15218f0f?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/5bce3b7ae368a17245089ce9f6aceaa527a31cc28e6d3cd10e417aee15218f0f?s=96&d=mm&r=g","caption":"allure"},"url":"https:\/\/allurewebsolutions.com\/author\/allure"}]}},"_links":{"self":[{"href":"https:\/\/allurewebsolutions.com\/wp-json\/wp\/v2\/posts\/2666","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/allurewebsolutions.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/allurewebsolutions.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/allurewebsolutions.com\/wp-json\/wp\/v2\/users\/9"}],"replies":[{"embeddable":true,"href":"https:\/\/allurewebsolutions.com\/wp-json\/wp\/v2\/comments?post=2666"}],"version-history":[{"count":0,"href":"https:\/\/allurewebsolutions.com\/wp-json\/wp\/v2\/posts\/2666\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/allurewebsolutions.com\/wp-json\/wp\/v2\/media\/2227"}],"wp:attachment":[{"href":"https:\/\/allurewebsolutions.com\/wp-json\/wp\/v2\/media?parent=2666"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/allurewebsolutions.com\/wp-json\/wp\/v2\/categories?post=2666"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/allurewebsolutions.com\/wp-json\/wp\/v2\/tags?post=2666"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}