• Hello there

    I have created my own WordPress site and my own theme (with Artisteer) about a year ago. The site looks nice and is working fine and doing what I want it to do, but recently I have been disappointed that Google thinks my site is SLOW ?? I have then decided to have a look into why things load so slowly and discovered that every single page was loading ALL of the CSS and JavaScript files use throughout my site. Many of these files are not necessary to be loaded for some pages and slow them down. There are for example some CSS files for the contact form, but those same files are loaded for my index page as well. There are many Javascript files needed for my photo gallery, but those same files are also loaded for my index page, contact page, blog page… Obviously this is redundant and makes the site slower than it should be.

    I am wondering, does anybody have any ideas on how to fix this problem?? I would like to load ONLY the NEEDED files for each page.

Viewing 3 replies - 1 through 3 (of 3 total)
  • You could use php code in the header or footer of your site to only load the files needed on the pages needed. Example:

    <?php if (is_home()) {?>
    	<?php include(TEMPLATEPATH . '/js/slider.php'); ?>
    <?php }?>
    Thread Starter johandeysel

    (@johandeysel)

    I see… thank you for the reply, but it still confuses me a little. Here is the code from my header file:

    [Code moderated as per the Forum Rules. Please use the pastebin]

    I think here is the part that controls the loading of the included files:

    <?php wp_head(); ?>

    Please tell me if I am wrong. Now, I know this just loads everything there is to load in terms of CSS and JS. How do I implement YOUR code suggestion or make the change to MINE to only load the necessary files for the specific page loading at the time??

    Please help, and keep in mind I am not an experienced coder ??

    Example:

    No! That’s a really bad example. You should be using wp_enqueue_script.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘How to exclude unnecessary CSS and JS files from loading?’ is closed to new replies.