2012-03-06 2 views
-1

기본적으로,이 작업은 페이지를 더 빨리로드 할 수 있도록 조금 더 깨끗하게 만드는 것입니다. 이렇게하는 방법이 있습니까?이 jQuery를 더 짧게 만들 수 있습니까?

내 머리의 코드는 다음과 같습니다 :

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml" dir="ltr" lang="en-US" xml:lang="en-US"> 
<head profile="http://gmpg.org/xfn/11"> 
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> 
<title>Steve A Tattoo Artist</title> 
<link rel="stylesheet" href="http://www.steveatattooartist.com/wp-content/themes/blue-and-grey/style.css" type="text/css" media="screen" /> 
<link href='http://fonts.googleapis.com/css?family=EB+Garamond' rel='stylesheet' type="text/css"> 
<!--[if lt ie 8]><link rel="stylesheet" href="http://www.steveatattooartist.com/wp-content/themes/blue-and-grey/styles/ie7.css" type="text/css" /><![endif]--> 
<!--[if lt ie 7]><link rel="stylesheet" href="http://www.steveatattooartist.com/wp-content/themes/blue-and-grey/styles/ie6.css" type="text/css" /><![endif]--> 
<link rel="pingback" href="http://www.steveatattooartist.com/xmlrpc.php" /> 

<!--DEMO CSS LINKS--> 
<link href="http:/www.steveatattooartist.com/wp-content/themes/blue-and-grey/demo.css" rel="stylesheet" type="text/css"/> 
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js" type="text/javascript"></script> 

<!--FANCY BOX REFS--> 
<script type="text/javascript" src="/fancybox/jquery.fancybox-1.3.4.pack.js" type="text/javascript"></script> 
<link rel="stylesheet" href="/fancybox/jquery.fancybox-1.3.4.css" type="text/css" media="screen" /> 

<!--GALLERIA--> 
<script src="/galleria/galleria-1.2.6.min.js"></script> 
<script src="/galleria/themes/classic/galleria.classic.min.js"></script> 
<script>Galleria.loadTheme('/galleria/themes/classic/galleria.classic.min.js');</script> 

<!--FANCY BOX JAVA--> 
<script> 
jQuery(document).ready(function() { 
/* This is basic - uses default settings */ 
$("a#single_image").fancybox(); 

/* Using custom settings */ 
$("a#inline").fancybox({ 
    'hideOnContentClick': true 
}); 

/* Apply fancybox to multiple items */ 
$("a.group").fancybox({ 
    'transitionIn' : 'elastic', 
    'transitionOut' : 'elastic', 
    'speedIn'  : 600, 
    'speedOut'  : 200, 
    'overlayShow' : false 
}); 
}); 
</script> 

<!--STEVE A DIV--> 

<script> 
jQuery(document).ready(function() { 
$("#firstpagename, #firstpagename2").click(function() { 
$("div#white").toggle(); 
$("div#v2black, div#v3black").hide(); 
}); 

$("#secondpagename, #secondpagename2").click(function() { 
$("div#v2black").toggle(); 
$("div#white, #v3black").hide(); 
}); 

$("#thirdpagename, #thirdpagename2").click(function() { 
$("div#v3black").toggle(); 
$("div#white, #v2black").hide(); 
}); 

$(".toggle").click(function(){ 
     $(".toggle").hide(); 
     $(this).toggle(); 
}); 

}); 
<!--MAIN TOP NAV SCROLLING--> 

$(window).scroll(function() { 
    if ($(this).scrollTop() >= 591) { 
     $(".altstevenav:hidden").show(); 
    } 
    else { 
     $(".altstevenav:visible").hide(); 
    } 
}); 

$(window).scroll(function() { 
    if ($(this).scrollTop() >= 591) { 
     $(".topwhiteborder:hidden").show(); 
    } 
    else { 
     $(".topwhiteborder:visible").hide(); 
    } 
}); 
</script> 
<!--END OF DEMO CSS LINKS--> 

<link rel="alternate" type="application/rss+xml" title="Steve A Tattoo Artist &raquo; Feed" href="http://www.steveatattooartist.com/?feed=rss2" /> 
<link rel="alternate" type="application/rss+xml" title="Steve A Tattoo Artist &raquo; Comments Feed" href="http://www.steveatattooartist.com/?feed=comments-rss2" /> 
<link rel='stylesheet' id='jquery.fancybox-css' href='http://www.steveatattooartist.com/wp-content/plugins/fancy-box/jquery.fancybox.css?ver=1.2.6' type='text/css' media='all' /> 
<script type='text/javascript' src='http://www.steveatattooartist.com/wp-includes/js/jquery/jquery.js?ver=1.7.1'></script> 
<script type='text/javascript' src='http://www.steveatattooartist.com/wp-content/plugins/fancy-box/jquery.fancybox.js?ver=1.2.6'></script> 
<script type='text/javascript' src='http://www.steveatattooartist.com/wp-content/plugins/fancy-box/jquery.easing.js?ver=1.3'></script> 
<script type='text/javascript' src='http://www.steveatattooartist.com/wp-includes/js/comment-reply.js?ver=20090102'></script> 
<link rel="EditURI" type="application/rsd+xml" title="RSD" href="http://www.steveatattooartist.com/xmlrpc.php?rsd" /> 
<link rel="wlwmanifest" type="application/wlwmanifest+xml" href="http://www.steveatattooartist.com/wp-includes/wlwmanifest.xml" /> 

<meta name="generator" content="WordPress 3.3.1" /> 
<link rel='canonical' href='http://www.steveatattooartist.com/' /> 
<script type="text/javascript"> 
    jQuery(document).ready(function($){ 
     var select = $('a[href$=".bmp"],a[href$=".gif"],a[href$=".jpg"],a[href$=".jpeg"],a[href$=".png"],a[href$=".BMP"],a[href$=".GIF"],a[href$=".JPG"],a[href$=".JPEG"],a[href$=".PNG"]'); 
     select.attr('rel', 'fancybox'); 
     select.fancybox(); 
    }); 
</script> 
    <style type="text/css">.recentcomments a{display:inline !important;padding:0 !important;margin:0 !important;}</style> 

나는 그것이 있어야하고 최대 정돈 할 수있는이 같은 깔끔한없는 생각! 어떤 도움을 ... 감사합니다

+5

코드 검토 SE 사이트 –

+1

에 게시하면 코드를 게시 할 때 약간의 존경심을가집니다. 모든 스크립트 및 링크 태그는 여기에 가치가 없으며 스크립트가 참조하는 중요한 부분은 HTML이 표시되지 않습니다 – charlietfl

+1

@MildFuzz : 제발 제안하지 마세요, 나는 그들이 현재의 형태로이 게시물을 원하지 않는다고 확신합니다. 나는 틀릴 수도있어, 이것이 Code Review를위한 적절한 자료라면 사과드립니다. –

답변

2

당신은 하나의 스크립트로 모든 JS을 가져올 수 :

<script type="text/javascript"> 
Galleria.loadTheme('/galleria/themes/classic/galleria.classic.min.js'); 

jQuery(document).ready(function() { 
    /* This is basic - uses default settings */ 
    $("a#single_image").fancybox(); 

    /* Using custom settings */ 
    $("a#inline").fancybox({ 
    'hideOnContentClick': true 
    }); 

    /* Apply fancybox to multiple items */ 
    $("a.group").fancybox({ 
    'transitionIn' : 'elastic', 
    'transitionOut' : 'elastic', 
    'speedIn'  : 600, 
    'speedOut'  : 200, 
    'overlayShow' : false 
    }); 

    // STEVE A DIV 
    $("#firstpagename, #firstpagename2").click(function() { 
    $("div#white").toggle(); 
    $("div#v2black, div#v3black").hide(); 
    }); 

    $("#secondpagename, #secondpagename2").click(function() { 
    $("div#v2black").toggle(); 
    $("div#white, #v3black").hide(); 
    }); 

    $("#thirdpagename, #thirdpagename2").click(function() { 
    $("div#v3black").toggle(); 
    $("div#white, #v2black").hide(); 
    }); 

    $(".toggle").click(function(){ 
    $(".toggle").hide(); 
    $(this).toggle(); 
    }); 


    // MAIN TOP NAV SCROLLING 

    $(window).scroll(function() { 
    if ($(this).scrollTop() >= 591) { 
     $(".altstevenav:hidden, .topwhiteborder:hidden").show(); 
    } 
    else { 
     $(".altstevenav:visible, .topwhiteborder:visible").hide(); 
    } 
    }); 

    var select = $('a[href$=".bmp"],a[href$=".gif"],a[href$=".jpg"],a[href$=".jpeg"],a[href$=".png"],a[href$=".BMP"],a[href$=".GIF"],a[href$=".JPG"],a[href$=".JPEG"],a[href$=".PNG"]'); 
    select.attr('rel', 'fancybox'); 
    select.fancybox(); 
}); 

</script> 

또한 하나의 라이브러리로 모든 JS 라이브러리 (fancybox, 갤러리아 등)을 결합 할 수 있습니다. js 파일. 그리고 위의 JS를 외부 scripts.js 파일로 이동하십시오.

또한 jquery를 두 번 호출하고 fancybox를 두 번 호출하므로 각 인스턴스를 하나씩 제거해야합니다.

WordPress에서 최적화 할 수 있는지 확실하지 않지만 JS 및 CSS 파일 수를 줄이는 것이 좋습니다. 가장 좋은 방법은 다른 JS (외부 또는 인라인)가없는 jquery, libraries.js 및 scripts.js에 대한 호출을 원할 것입니다.

+0

건배! 감사합니다. –

+0

내가 변경할 경우 작동하지 않습니다 var select = jQuery ('img [src $ = ".bmp"], img [src $ = ".gif"], img [src $ = ". jpg"], img [src $ img src = ".jpg"], img [src $ = ".jpg"], img [src $ = ". , img [src $ = ".JPG"], img [src $ = ". PNG"] '); \t \t select.attr ('rel', 'fancybox'); \t \t select.fancybox(); – Thoman

관련 문제