2017-12-07 6 views
0

에서 자바 스크립트와 CSS를 그 Html.AppendScriptParts("~/Scripts/jquery-1.10.2.min.js",false,true);3.80 nopcommerce 청산 차단 내가 좋아하는 nopcommerce 3.80에 <code>Html.AppendScriptParts</code> 방법의 "비동기"속성을 사용하고 스크롤없이 볼 수있는 내용

구글 페이지 속도 도구는 그것에게 높은 점수를주고

하는 내가 JS와 CSS를 사용하지 않는 enter image description here enter image description here

(... 세븐에서 오는 플러그인을 스파이크 NIVO 슬라이더, 아약스 필터) enter image description here 그러나 웹 사이트의 다른 기능에 효과를 보인다 내가 예상된다 nopcommerce에서 번들링 기능. 지금 내 장면 목록에서 가장 좋은 솔루션이 무엇인지 말해 주실 수 있습니까? 도움이 매우 적절합니다. 정말 고마워요.

@using Nop.Core.Domain.Common; 
@using Nop.Core.Domain.Seo 
@using Nop.Core.Infrastructure; 
@{ 
    var displayMiniProfiler = EngineContext.Current.Resolve<Nop.Core.Domain.StoreInformationSettings>().DisplayMiniProfilerInPublicStore; 

    Html.AppendScriptParts("~/Scripts/public.ajaxcart.js"); 
    Html.AppendScriptParts("~/Scripts/public.common.js"); 
    Html.AppendScriptParts("~/Scripts/jquery-migrate-1.2.1.min.js"); 
    Html.AppendScriptParts("~/Scripts/jquery-ui-1.10.3.custom.min.js"); 
    Html.AppendScriptParts("~/Scripts/jquery.validate.unobtrusive.min.js"); 
    Html.AppendScriptParts("~/Scripts/jquery.validate.min.js"); 
    Html.AppendScriptParts("~/Scripts/jquery-1.10.2.min.js",false,true); 
    var commonSettings = EngineContext.Current.Resolve<CommonSettings>(); 
    if (commonSettings.RenderXuaCompatible) 
    { 
     Html.AppendHeadCustomParts(string.Format("<meta http-equiv=\"X-UA-Compatible\" content=\"{0}\"/>", commonSettings.XuaCompatibleValue)); 
    } 
    var seoSettings = EngineContext.Current.Resolve<SeoSettings>(); 
    if (!string.IsNullOrEmpty(seoSettings.CustomHeadTags)) 
    { 
     Html.AppendHeadCustomParts(seoSettings.CustomHeadTags); 
    } 
} 
<!DOCTYPE html> 
<[email protected](this.ShouldUseRtlTheme() ? Html.Raw(" dir=\"rtl\"") : null) @Html.NopPageCssClasses()> 
<head> 
    <title>@Html.NopTitle()</title> 
    <meta http-equiv="Content-type" content="text/html;charset=UTF-8" /> 
    <meta name="description" content="@(Html.NopMetaDescription())" /> 
    <meta name="keywords" content="@(Html.NopMetaKeywords())" /> 
    <meta name="generator" content="nopCommerce" /> 
    <meta name="viewport" content="width=device-width, initial-scale=1" /> 
    @Html.NopHeadCustom() 
    @Html.Partial("Head") 
    @Html.Widget("head_html_tag") 
    @Html.NopCssFiles(this.Url, ResourceLocation.Head) 
    @Html.NopScripts(this.Url, ResourceLocation.Head) 
    @Html.NopCanonicalUrls() 
    @Html.Action("RssHeaderLink", "News") 
    @Html.Action("RssHeaderLink", "Blog") 
    @Html.Action("Favicon", "Common") 
    @if (displayMiniProfiler) 
    { 
     @StackExchange.Profiling.MiniProfiler.RenderIncludes() 
    } 
</head> 
<body> 
    @RenderBody() 
    @Html.NopCssFiles(this.Url, ResourceLocation.Foot) 
    @Html.NopScripts(this.Url, ResourceLocation.Foot) 


</body> 
</html> 

enter image description here

+0

콘솔을 확인 했습니까? 어떤 오류가 있습니까? –

+0

네, 그랬습니다. 거의 오류입니다 : "Uncaught ReferenceError : jQuery가 정의되지 않았습니다". 콘솔에 오류에 대한 스크린 샷을 첨부했습니다. 감사합니다. –

+0

감사합니다 @Div, 내 웹 사이트 URL을 보여 주실 수 있으며 귀하의 솔루션이 무엇인지 알려주십시오. –

답변

1

첫째,이 일곱 스파이크 플러그인 관련이없는 것 :

여기 _Root.head.cshtml의 내 코드입니다. 이 문제는 async 동작으로 인해 발생합니다. jquery 파일을 비동기로 만들면 응용 프로그램이 해당 파일을로드하고 다음 js 파일을로드 할 때까지 기다리지 않는다는 의미입니다. 하지만 다른 js 파일은 첫 번째 주 파일에 의존하기 때문에 오류가 발생합니다.

의 현재 시나리오를 이해하자, 기본 코드는 다음과 같습니다 JS 파일의 순서는이 경우

Html.AppendScriptParts("~/Scripts/public.ajaxcart.js"); 
Html.AppendScriptParts("~/Scripts/public.common.js"); 
Html.AppendScriptParts("~/Scripts/jquery-migrate-1.2.1.min.js"); 
Html.AppendScriptParts("~/Scripts/jquery-ui-1.10.3.custom.min.js"); 
Html.AppendScriptParts("~/Scripts/jquery.validate.unobtrusive.min.js"); 
Html.AppendScriptParts("~/Scripts/jquery.validate.min.js"); 
Html.AppendScriptParts("~/Scripts/jquery-1.10.2.min.js"); 

: enter image description here

지금 비동기 JQuery와 분의 js 파일을로드합니다.

Html.AppendScriptParts("~/Scripts/jquery-1.10.2.min.js", false, true); 

그리고 확인 콘솔 : 오류 (들)을 얻을 것이다 이러한 변화와

enter image description here

.
이 문제를 해결하려면 js min 파일을 특정 순서로 종속성 기준으로로드해야합니다.

사이드 노트 :이 문제는 기본 코드에서도 발생합니다! nopCommerce 3.80 및 3.90으로 테스트했습니다.

+0

@Div, 고맙습니다. 제발 제가 제 발언을 고칠 수있는 방법을 설명해 주시겠습니까? –

+0

"의존성에 따라 특정 순서로 js min 파일로드"라는 의미는 무엇입니까? –

+0

@HuyTa,'jquery-1.10.2.min'은 실제 jQuery 파일이므로 먼저로드하고 다른 js 라이브러리/파일을로드해야합니다. –