Title: Optimizing when to call wp_register_script?
Last modified: August 19, 2016

---

# Optimizing when to call wp_register_script?

 *  [georgecobb](https://wordpress.org/support/users/georgecobb/)
 * (@georgecobb)
 * [16 years, 1 month ago](https://wordpress.org/support/topic/optimizing-when-to-call-wp_register_script/)
 * Hi, I’m implementing some CDN libraries using a popular method seen here (basically
   de-register and register):
 * [http://digwp.com/2009/06/use-google-hosted-javascript-libraries-still-the-right-way/](http://digwp.com/2009/06/use-google-hosted-javascript-libraries-still-the-right-way/)
 * It’s working great, but I have a ‘best practices’ question. I simply placed the
   code in functions.php (of my theme) as suggested.
 * So, does WP actually deregister (wp_deregister_script) and re-register (wp_register_script)
   on each and every page requested from the front end?
 * In other words, does code **not** contained within a function (located in ‘functions.
   php’) fire for **every** request?
 * If that’s the case, is it smarter to create a function called ‘inject_cdn_scripts()’,
   for example, and somehow only call that function **once** upon a WP initialization
   hook (maybe using add_action)?
 * I’m new to WP, coming from a .NET background, so I’m thinking it would be similar
   to placing this function in global.asax > Application_Start().
 * Thanks!

Viewing 1 replies (of 1 total)

 *  Thread Starter [georgecobb](https://wordpress.org/support/users/georgecobb/)
 * (@georgecobb)
 * [16 years, 1 month ago](https://wordpress.org/support/topic/optimizing-when-to-call-wp_register_script/#post-1459573)
 * Hi,
 * Really hate to bump… Just curious if anyone has any thoughts on this and whether
   or not I’m even understanding the architecture of functions.php correctly.
 * Thanks!

Viewing 1 replies (of 1 total)

The topic ‘Optimizing when to call wp_register_script?’ is closed to new replies.

 * 1 reply
 * 1 participant
 * Last reply from: [georgecobb](https://wordpress.org/support/users/georgecobb/)
 * Last activity: [16 years, 1 month ago](https://wordpress.org/support/topic/optimizing-when-to-call-wp_register_script/#post-1459573)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
