Search code examples
javascriptperformancefont-facehead

Site fonts and javascripts running slow due to excess scripts


I have a site that's taking a really long time to load its font-face kit styles, as well as a couple of other scripts that are running funny. This is happening because my scripts are all jumbled in my section, but I'm afraid that I don't know enough about these scripts to clean up my files correctly. Can anyone take a stab at suggesting some things I could do to clean this up and improve the speed and functionality of my site, particularly with loading the font-face text more quickly? Any examples or specific references would be great - I'm pretty lost on what all exactly is going on with these scripts. Here's what's happening in my :

<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="viewport" content="width=device-width,initial-scale=0.3"> 
    <meta name="google-translate-customization" content="d378d0a5e57245bf-c2ed76fd752675aa-g7014305900f205ae-13"></meta>

    <title>{embed:title}</title>
    <style type="text/css" media="screen">
         @import url("/common/css/all.css");
         @import url("/common/font_face/stylesheet.css");
         @import url("/common/css/jcf.css");
    </style>

    <script type="text/javascript" src="/common/js/jquery-1.8.3.min.js"></script>
    <script type="text/javascript" src="/common/js/jquery.main.js"></script>

    <!--fancybox script starts here-->  
    <script type="text/javascript" src="/common/js/fancybox/lib/jquery.mousewheel-3.0.6.pack.js"></script>  
    <script type="text/javascript" src="/common/js/fancybox/source/jquery.fancybox.js?v=2.0.6"></script>
    <link rel="stylesheet" type="text/css" href="/common/js/fancybox/source/jquery.fancybox.css?v=2.0.6" media="screen" />
    <link rel="stylesheet" href="/common/js/fancybox/source/helpers/jquery.fancybox-buttons.css?v=1.0.2" type="text/css" media="screen" />
    <script type="text/javascript" src="/common/js/fancybox/source/helpers/jquery.fancybox-buttons.js?v=1.0.2"></script>
    <script type="text/javascript" src="/common/js/fancybox/source/helpers/jquery.fancybox-media.js?v=1.0.0"></script>
    <link rel="stylesheet" href="/common/js/fancybox/source/helpers/jquery.fancybox-thumbs.css?v=2.0.6" type="text/css" media="screen" />
    <script type="text/javascript" src="/common/js/fancybox/source/helpers/jquery.fancybox-thumbs.js?v=2.0.6"></script>
    <script type="text/javascript">
        $(document).ready(function() {
            // fancybox for html pages
            $(".fancylink").fancybox({
                'height' : '100%',
                'autoScale' : false,
                'transitionIn' : 'none',
                'transitionOut' : 'none',
                'type' : 'iframe'
             });
             $(".fancylinksm").fancybox({
                'height' : 'auto',
                'autoScale' : false,
                'transitionIn' : 'none',
                'transitionOut' : 'none',
                'type' : 'iframe'
             });

             // fancybox for vimeo
             $(".vimeo").fancybox({
                width: 781,
                height: 440,
                type: 'iframe',
                fitToView : false,
                wrapCSS : 'fancybox-nav-video'
             });

             $('.fancybox').fancybox({
                padding : 0,
                openEffect  : 'elastic'
             });

             $(".fancybox").fancybox({
                wrapCSS    : 'fancybox-custom',
                closeClick : true,
                helpers : {
                   overlay : {
                      css : {
                         'background-color' : '#000'
                      }
                   },
                   thumbs : {
                      width : 50,
                      height : 50
                   }
                }
            });
         });
       $("a[href$='.jpg'],a[href$='.jpeg'],a[href$='.png'],a[href$='.gif']").attr('rel', 'gallery').fancybox();      
    </script>
    <!--fancybox script ends here-->
    <link rel="shortcut icon" href="/common/images/cut-and-paste-logo.ico" type="image/x-icon" />
</head>

UPDATED CODE I compiled all of my scripts into one 'compiled.js' file and changed all @import calls to s, however it is still not making my fonts load any faster. Here is the new section:

<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="viewport" content="width=device-width,initial-scale=0.3"> 
    <meta name="google-translate-customization" content="d378d0a5e57245bf-c2ed76fd752675aa-g7014305900f205ae-13"></meta>

    <!-- meta data goes here -->
    <title>{embed:title}</title>

    <link rel='stylesheet' type='text/css' href='/common/font_face/stylesheet.css'>
    <link rel='stylesheet' type='text/css' href='/common/css/all.css'>
    <link rel='stylesheet' type='text/css' href='/common/css/jcf.css'>
    <link rel="stylesheet" type="text/css" href="/common/css/jquery.fancybox.css?v=2.0.6" media="screen" />
    <link rel="stylesheet" href="/common/css/jquery.fancybox-buttons.css?v=1.0.2" type="text/css" media="screen" />
    <link rel="stylesheet" href="/common/css/jquery.fancybox-thumbs.css?v=2.0.6" type="text/css" media="screen" />
    <link rel="shortcut icon" href="/common/images/characterized_logo_16x16.ico" type="image/x-icon" />
    <!--[if lt IE 9]><link rel="stylesheet" type="text/css" href="css/ie.css" media="screen"/><![endif]-->  

    <script type="text/javascript" src="/common/js/compiled.js"></script>
</head>

Solution

  • After optimizing my scripts, everything was running a bit faster, but not perfectly. As an experiment, in my main CSS file, I deleted the call for all of the @font-faces (there were about 10 of them).

    I deleted these:

    @font-face {
    font-family: 'TradeGothicLTStdCnNo.18Ob';
    src: url('../fonts/tradegothicltstd-cn18obl-webfont.eot');
    src: url('../fonts/tradegothicltstd-cn18obl-webfont.eot?#iefix') format('embedded-opentype'),
    url('../fonts/tradegothicltstd-cn18obl-webfont.woff') format('woff'),
    url('../fonts/tradegothicltstd-cn18obl-webfont.ttf') format('truetype'),
    url('../fonts/tradegothicltstd-cn18obl-webfont.svg#TradeGothicLTStdCnNo.18Ob') format('svg');
    font-weight: normal;
    font-style: normal;
    }
    

    But am still calling this font css in my header

    <link rel='stylesheet' type='text/css' href='/font_face/stylesheet.css'>
    

    After doing that, everything is running smoothly, quickly, and across multiple browswers. Looks like @font-face was the real issue here. I still have my fonts being pulled through java script, so I have all of my custom fonts with no lag.