Bläddra i källkod

moar optimizatiuionp

Moritz Schmidt 9 år sedan
förälder
incheckning
cb5f925a9e
3 ändrade filer med 40 tillägg och 46 borttagningar
  1. 32 0
      dist/scripts.js
  2. 0 34
      footer.php
  3. 8 12
      functions.php

+ 32 - 0
dist/scripts.js

@@ -0,0 +1,32 @@
+jQuery( document ).ready(function($) {
+  $("link[media=\"1\"]").attr("media", "all"); // load css async
+
+  $('#nav').Stickyfill(); // NAV
+
+  $(document).on("click", "nav.navbar #ams-topnav[aria-expanded=\"true\"] a", function() {
+    $('.navbar-toggler').click();
+  });
+
+  /** TdA Carousel **/
+
+  $('.owl-carousel').slick({
+      dots: false,
+      infinite: true,
+      variableWidth: true,
+      autoplay: true,
+      lazyLoad: 'progressive',
+      swipeToSlide: true,
+      waitForAnimate: false,
+      nextArrow: '<span class="icon-next" aria-hidden="true"><i class="fa fa-chevron-right" aria-hidden="true"></i></span>',
+      prevArrow: '<span class="icon-prev" aria-hidden="true"><i class="fa fa-chevron-left" aria-hidden="true"></i></span>',
+  });
+
+  $(document).on('click', 'a.scroll-link[href^="#"]', function(e){
+    e.preventDefault();
+
+    $('html, body').animate({
+      scrollTop: $( $.attr(this, 'href') ).offset().top
+    }, 500);
+  });
+
+});

+ 0 - 34
footer.php

@@ -11,39 +11,5 @@
     </div>
 
     <?php wp_footer(); ?>
-
-    <!-- jQuery first, then Bootstrap JS. -->
-    <script type="text/javascript">
-      jQuery( document ).ready(function($) {
-        $('#nav').Stickyfill(); // NAV
-
-        $(document).on("click", "nav.navbar #ams-topnav[aria-expanded=\"true\"] a", function() {
-          $('.navbar-toggler').click();
-        });
-
-        /** TdA Carousel **/
-
-        $('.owl-carousel').slick({
-            dots: false,
-            infinite: true,
-            variableWidth: true,
-            autoplay: true,
-            lazyLoad: 'progressive',
-            swipeToSlide: true,
-            waitForAnimate: false,
-            nextArrow: '<span class="icon-next" aria-hidden="true"><i class="fa fa-chevron-right" aria-hidden="true"></i></span>',
-            prevArrow: '<span class="icon-prev" aria-hidden="true"><i class="fa fa-chevron-left" aria-hidden="true"></i></span>',
-        });
-
-        $(document).on('click', 'a.scroll-link[href^="#"]', function(e){
-          e.preventDefault();
-
-          $('html, body').animate({
-            scrollTop: $( $.attr(this, 'href') ).offset().top
-          }, 500);
-        });
-
-      });
-    </script>
   </body>
 </html>

+ 8 - 12
functions.php

@@ -11,10 +11,10 @@ register_nav_menu("primary", "Top Menu");
 /** STYLES **/
 
 function ams_enqueue_styles() {
-  wp_enqueue_style('bootstrap', get_template_directory_uri() . '/dist/bootstrap/bootstrap.css', array(), '4.0.0-3');
-  wp_enqueue_style('slick', get_template_directory_uri() . '/dist/slick/slick.css', array(), '1.6.0');
-  wp_enqueue_style('slick-theme', get_template_directory_uri() . '/dist/slick/slick-theme.css', array("slick"), '1.6.0');
-  wp_enqueue_style('ams', get_template_directory_uri() . '/style.css', array("slick", "slick-theme", "bootstrap"), '1.0.0');
+  wp_enqueue_style('bootstrap', get_template_directory_uri() . '/dist/bootstrap/bootstrap.css', array(), '4.0.0-3', true);
+  wp_enqueue_style('slick', get_template_directory_uri() . '/dist/slick/slick.css', array(), '1.6.0', true);
+  wp_enqueue_style('slick-theme', get_template_directory_uri() . '/dist/slick/slick-theme.css', array("slick"), '1.6.0', true);
+  wp_enqueue_style('ams', get_template_directory_uri() . '/style.css', array("slick", "slick-theme", "bootstrap"), '1.0.0', true);
 }
 
 function ams_enqueue_scripts() {
@@ -24,6 +24,7 @@ function ams_enqueue_scripts() {
   wp_enqueue_script('bootstrap', get_template_directory_uri() . '/dist/bootstrap/bootstrap.js', array("jquery"), '4.0.0-3', true);
   wp_enqueue_script('stickyfill', get_template_directory_uri() . '/dist/stickyfill/stickyfill.js', array("jquery"), '1.1.4', true);
   wp_enqueue_script('slick', get_template_directory_uri() . '/dist/slick/slick.js', array("jquery"), '1.6.0', true);
+  wp_enqueue_script('scripts', get_template_directory_uri() . '/dist/scripts.js', array("jquery"), '1.0.0', true);
 }
 
 add_action('wp_enqueue_scripts', 'ams_enqueue_styles');
@@ -758,15 +759,10 @@ add_filter( 'wp_title', 'ams_modify_titles', 10, 2 );
 
 
 function my_async_scripts( $tag, $handle, $src ) {
-    // the handles of the enqueued scripts we want to async
-    $async_scripts = array( 'jquery', 'bootstrap', 'stickyfill', 'slick', 'wp-embed');
-
-    if ( in_array( $handle, $async_scripts ) ) {
-        return '<script type="text/javascript" src="' . $src . '" async></script>' . "\n";
-    }
-
-    return $tag;
+  return '<script type="text/javascript" src="' . $src . '" async></script>' . "\n";
 }
 add_filter( 'script_loader_tag', 'my_async_scripts', 10, 3 );
 
+
+
 ?>