Ask your WordPress questions! Pay money and get answers fast! (more info)

CDN in WP-ADMIN WordPress

  • SOLVED

I am using WP-Super-Cache plugin and it comes with a CDN module.
I noticed that the CDN module does not rewrite URLs when in wp-admin, but works fine in public pages.

Can someone provide a modification to ossdl-cdn.php so that it will also rewrite the URLs to CDN when logged in to wp-admin?

Thanks.

Answers (3)

2014-04-02

Dbranes answers:

Hi Raymond

Good advices from others here, but you can try to change the <em>base_url</em> for the default scripts and styles with the following:

add_action( 'admin_init', 'wpq_admin_init' );

function wpq_admin_init(){

global $wp_scripts, $wp_styles;

$wp_styles->base_url = 'http://cdn.example.com/';
$wp_scripts->base_url = 'http://cdn.example.com/';
}


where you have:

define( 'CONCATENATE_SCRIPTS', FALSE );


in your <em>wp-config.php</em> file.

---

You can also try the <em>script_loader_src</em> filter:

is_admin() && add_filter( 'script_loader_src', 'wpq_script_loader_src' );
function wpq_script_loader_src( $src ){
$src = str_ireplace( $old_domain, $new_domain , $src );
return $src;
}


and similarly for the <em>style_loader_src </em>filter.


raymond comments:

Thanks Birgir, that worked!

Well the reason why I wanted to offload all the static files to CDN is because I've recently moved to an all HTTPS and I don't want to burden my server.

There seems to be a few more files not loading from CDN after implementation.

/wp-admin/css/colors.min.css?ver=3.8.1

From plugins:
/wp-content/plugins/akismet/akismet.css?ver=2.6.0
/wp-content/plugins/download-monitor/css/wp-download_monitor27.css
/wp-content/plugins/microkids-related-posts/microkids-related-posts-admin.css?v=4.0.1
/wp-content/plugins/akismet/akismet.js?ver=2.6.0
/wp-content/plugins/microkids-related-posts/microkids-related-posts.js?v=4.0.1
/wp-content/plugins/wordpress-seo-premium/js/wp-seo-admin-global.min.js?ver=1.5.2.5


Dbranes comments:

ok, see the updated answer.


raymond comments:

Do I need to change the "$old_domain, $new_domain" to reflect on my original domain and CDN?


Dbranes comments:

yes


raymond comments:

Works out really well.

It seems that there are also static files being loaded from wp-admin folder.
Some files such as:

/wp-admin/images/resize.gif
/wp-admin/images/wpspin_light.gif
/wp-admin/images/wpspin_light-2x.gif

Would be great if they can be loaded from CDN as well. Thanks!

2014-04-01

zebra webdesigns answers:

Hello Raymond

Your question is little confusing.
Why you need to rewrite the URL inside wordpress admin.


raymond comments:

I only need to "rewrite static files" (such as .JS and .CSS) from wp-admin to CDN.


zebra webdesigns comments:

Raymond Can you add me in skype
Skype ID: bhuvan530531

2014-04-02

Francisco Javier Carazo Gil answers:

Raymond,

A CDN inside back-end has no much sense, the user is you and the updates can be problematic. Maybe many users access to dashboard (in that case it can be useful) but MySQL queries time in back-end take much time so it wouldn't be a very good solution.


raymond comments:

I have thought about the consequences weighing the pros and cons, but I would still very much like to cache the static files loaded in wp-admin. Thank you.


Francisco Javier Carazo Gil comments:

Raymond,

Think that the browsers will cache all this info: JS and CSS, until you don't change version in wp_enqueues... so another idea to provide agains it.