programing

wp_enqueue_script()를 사용하여 외부 스크립트를 큐잉해야 합니까?

newnotes 2023. 4. 5. 22:12
반응형

wp_enqueue_script()를 사용하여 외부 스크립트를 큐잉해야 합니까?

그 함수로 외부 스크립트를 큐잉하는 것이 맞습니까?작동은 되는데 사이트 열기가 느려지지 않나요?

wp_register_script( 'google-maps', 'http://maps.googleapis.com/maps/api/js?sensor=true', null, null, true );
wp_register_script( 'jsapi', 'https://www.google.com/jsapi', null, null, true );
wp_register_script( 'bootstrap', 'https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js', null, null, true );
wp_register_script( 'unveil', get_template_directory_uri() . '/new-js/jquery.unveil.min.js', null, null, true );

아니요, 사이트 속도가 느려지지 않습니다(적어도 사용하지 않는 이유가 될 정도는 아닙니다).이것은 WordPress에서 모든 유형의 스크립트를 큐잉하는 올바른 방법입니다.이 함수가 하는 모든 것은 적절한 것을 추가하는 것이다.<link>HTML에 태그(의존관계 포함)<head>.

그러나 어떤 이유로 인해 코드에 종속성이 포함되어 있지 않습니다.예를 들어 부트스트랩에는 jQuery가 필요하므로 함수에 포함해야 합니다.

wp_enqueue_script( 'bootstrap', 'https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js', array('jquery'), '3.3.5', true );

위와 같이 다음 명령어를 사용하는 것도 고려해야 합니다.wp_register_script()한 발짝도 덜 수 있으니까.

언급URL : https://stackoverflow.com/questions/35224806/should-i-enqueue-external-scripts-using-wp-enqueue-script

반응형