Title: Why not external javascript?
Last modified: August 31, 2016

---

# Why not external javascript?

 *  Resolved [MTO](https://wordpress.org/support/users/mto/)
 * (@mto)
 * [10 years, 5 months ago](https://wordpress.org/support/topic/why-not-external-javscript/)
 * Hello,
    Really like this plugin and service, but I have doubts about the inline
   java-script it attaches to every single page. I am afraid it affects page speed
   load performance, as the code is not reused, when it could perfectly be hosted
   in a external javascript file.
 * For example, this is what I see attached in the source code of every single page
   I have:
 *     ```
       <script src="https://cdn.onesignal.com/sdks/OneSignalSDK.js" async></script>
           <script>
   
             var OneSignal = OneSignal || [];
   
             OneSignal.push( function() {
               OneSignal.SERVICE_WORKER_UPDATER_PATH = "OneSignalSDKUpdaterWorker.js.php";
               OneSignal.SERVICE_WORKER_PATH = "OneSignalSDKWorker.js.php";
               OneSignal.SERVICE_WORKER_PARAM = { scope: '/' };
   
               OneSignal.setDefaultNotificationUrl("http://www.websitename.com");
               var oneSignal_options = {};
   
               oneSignal_options['wordpress'] = true;
       oneSignal_options['appId'] = 'idnumber';
       oneSignal_options['autoRegister'] = false;
       oneSignal_options['welcomeNotification'] = { };
       oneSignal_options['welcomeNotification']['title'] = "Website Name";
       oneSignal_options['welcomeNotification']['message'] = "Gracias por suscribirte";
       oneSignal_options['welcomeNotification']['url'] = "http://www.websitename.com";
       oneSignal_options['subdomainName'] = "websitename";
       oneSignal_options['safari_web_id'] = "web.onesignal.auto.number";
       oneSignal_options['promptOptions'] = { };
       oneSignal_options['promptOptions']['actionMessage'] = 'quiere notificarte cuando haga falta';
       oneSignal_options['promptOptions']['exampleNotificationTitleDesktop'] = '¡Eres una mujer hermosa!';
       oneSignal_options['promptOptions']['exampleNotificationMessageDesktop'] = 'Las notificaciones aparecerán así:';
       oneSignal_options['promptOptions']['exampleNotificationTitleMobile'] = '¡Eres una mujer hermosa!';
       oneSignal_options['promptOptions']['exampleNotificationMessageMobile'] = 'Las notificaciones aparecerán así:';
       oneSignal_options['promptOptions']['exampleNotificationCaption'] = '(podrás borrarte cuando quieras)';
       oneSignal_options['promptOptions']['acceptButtonText'] = 'CONTINUAR';
       oneSignal_options['promptOptions']['cancelButtonText'] = 'NO GRACIAS';
       oneSignal_options['promptOptions']['showCredit'] = false;
       oneSignal_options['notifyButton'] = { };
       oneSignal_options['notifyButton']['enable'] = true;
       oneSignal_options['notifyButton']['position'] = 'bottom-right';
       oneSignal_options['notifyButton']['theme'] = 'default';
       oneSignal_options['notifyButton']['size'] = 'medium';
       oneSignal_options['notifyButton']['prenotify'] = true;
       oneSignal_options['notifyButton']['showCredit'] = false;
       oneSignal_options['notifyButton']['text'] = {};
       oneSignal_options['notifyButton']['text']['message.prenotify'] = 'Pulsa aquí para suscribirte a notificaciones';
       oneSignal_options['notifyButton']['text']['tip.state.unsubscribed'] = 'Suscribirme a notificaciones';
       oneSignal_options['notifyButton']['text']['tip.state.subscribed'] = 'Ahora ya estás suscrita';
       oneSignal_options['notifyButton']['text']['tip.state.blocked'] = 'Has bloqueado las notificaciones';
       oneSignal_options['notifyButton']['text']['message.action.subscribed'] = 'Gracias por suscribirte';
       oneSignal_options['notifyButton']['text']['message.action.resubscribed'] = 'Ya estás suscrita a notificaciones';
       oneSignal_options['notifyButton']['text']['message.action.unsubscribed'] = 'Ya no recibirás más notificaciones';
       oneSignal_options['notifyButton']['text']['dialog.main.title'] = 'Administrar notificaciones del sitio';
       oneSignal_options['notifyButton']['text']['dialog.main.button.subscribe'] = 'SUSCRIBIRME';
       oneSignal_options['notifyButton']['text']['dialog.main.button.unsubscribe'] = 'BORRARME';
       oneSignal_options['notifyButton']['text']['dialog.blocked.title'] = 'Bloquear notificaciones';
       oneSignal_options['notifyButton']['text']['dialog.blocked.message'] = 'Sigue estas instrucciones para permitir notificaciones:';
   
               OneSignal.init(oneSignal_options);
             });
   
             function documentInitOneSignal() {
               var oneSignal_elements = document.getElementsByClassName("OneSignal-prompt");
   
               var oneSignalLinkClickHandler = function(event) { OneSignal.push(['registerForPushNotifications']); event.preventDefault(); };        for(var i = 0; i < oneSignal_elements.length; i++)
                 oneSignal_elements[i].addEventListener('click', oneSignalLinkClickHandler, false);
             }
   
             if (document.readyState === 'complete') {
                  documentInitOneSignal();
             }
             else {
                  window.addEventListener("load", function(event){
                      documentInitOneSignal();
                 });
             }
           </script>
       ```
   
 * Any possibility upcoming plugin updates solve this soon? Thanks.
 * Placing JavaScripts in external files has some advantages:
    1. It separates HTML and code
    2. It makes HTML and JavaScript easier to read and maintain
    3. Cached JavaScript files can speed up page loads
 * [https://wordpress.org/plugins/onesignal-free-web-push-notifications/](https://wordpress.org/plugins/onesignal-free-web-push-notifications/)

Viewing 1 replies (of 1 total)

 *  Plugin Author [OneSignal Push Notifications](https://wordpress.org/support/users/onesignal/)
 * (@onesignal)
 * [10 years, 5 months ago](https://wordpress.org/support/topic/why-not-external-javscript/#post-7117777)
 * Hi,
 * Thanks for contacting us! There isn’t any reason why we couldn’t place this in
   an external JavaScript file and reference it on the page, but our current method
   should not be slowing down your site.
 * The majority of our code is contained in our web SDK (referenced at OneSignalSDK.
   js) and is asynchronously loaded from our CDN with the “async” attribute. Because
   the SDK is loaded asynchronously, it does not impact page load.
 * The remaining code is a relatively small amount of initialization code. This 
   initialization code executes after the web SDK is fully loaded, so that the page
   can load in the meantime. Most pages should be cached even if they aren’t JavaScript
   files, so these lines are probably cached on most sites with the page’s HTML.
 * Our code on your page should be reused if your page is also being cached.
 * With the latest release of our WordPress plugin

Viewing 1 replies (of 1 total)

The topic ‘Why not external javascript?’ is closed to new replies.

 * ![](https://ps.w.org/onesignal-free-web-push-notifications/assets/icon.svg?rev
   =3003897)
 * [OneSignal - Web Push Notifications](https://wordpress.org/plugins/onesignal-free-web-push-notifications/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/onesignal-free-web-push-notifications/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/onesignal-free-web-push-notifications/)
 * [Active Topics](https://wordpress.org/support/plugin/onesignal-free-web-push-notifications/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/onesignal-free-web-push-notifications/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/onesignal-free-web-push-notifications/reviews/)

## Tags

 * [code](https://wordpress.org/support/topic-tag/code/)
 * [javascript](https://wordpress.org/support/topic-tag/javascript/)

 * 1 reply
 * 2 participants
 * Last reply from: [OneSignal Push Notifications](https://wordpress.org/support/users/onesignal/)
 * Last activity: [10 years, 5 months ago](https://wordpress.org/support/topic/why-not-external-javscript/#post-7117777)
 * Status: resolved