Serving wp-includes (front-end) javascript from a different domain?

Okay, I’ve tried numerous (literally) codes and methods, and failed miserably. So, like I said in the question, the only safe way seems to be re-registering (unregistering and enqueuing) the scripts.

The Scripts:

http://mywebsite.com/wp-includes/js/comment-reply.js
http://mywebsite.com/wp-includes/js/quicktags.js

Should be served from:

http://example.com/wp-includes/js/comment-reply.js
http://example.com/wp-includes/js/quicktags.js

Code in functions.php:

add_action('wp_enqueue_scripts','wpse56742_register_script');
function wpse56742_register_script(){

    //Register and enqueue Comment Reply script
    wp_deregister_script('comment-reply');
    wp_register_script('comment-reply', 'http://example.com/wp-includes/js/comment-reply.js', false, false);
    wp_enqueue_script( 'comment-reply' );

    //Re-register quicktags script
    wp_deregister_script('quicktags');
    wp_register_script('quicktags', 'http://example.com/wp-includes/js/quicktags.js', false, false, true);
    wp_localize_script( 'quicktags', 'quicktagsL10n', array(
        'wordLookup' => __('Enter a word to look up:'),
        'dictionaryLookup' => esc_attr(__('Dictionary lookup')),
        'lookup' => esc_attr(__('lookup')),
        'closeAllOpenTags' => esc_attr(__('Close all open tags')),
        'closeTags' => esc_attr(__('close tags')),
        'enterURL' => __('Enter the URL'),
        'enterImageURL' => __('Enter the URL of the image'),
        'enterImageDescription' => __('Enter a description of the image'),
        'fullscreen' => __('fullscreen'),
        'toggleFullscreen' => esc_attr( __('Toggle fullscreen mode') ),
        'textdirection' => esc_attr( __('text direction') ),
        'toggleTextdirection' => esc_attr( __('Toggle Editor Text Direction') )
    ));
    wp_enqueue_script( 'quicktags' );

}

As for the code used in wp_localize_script, I got it straight from trunk (you can also get it for your WP version, for example, for WP 3.4, the link would be http://core.svn.wordpress.org/tags/3.4/wp-includes/media.php).


FAQ: Why is quicktags.js loaded in the front-end in the first place? Because I am using the plugin — Basic Comment Quicktags

Leave a Comment