Google Custom Search placeholder function in JavaScript Problem:

We have a Google Custom Search function that replaces the input placeholder attribute and it works okay. 

Would you be so kind and help me with reviewing it, and if possible, provide an efficient function to replace this function with (also hoping that it would work with older version of IE and other browsers, not very necessary though): 

Placeholder Script:

// google search placeholder
(function() {   
    var cx = '!!!!!!!!!!!!!!!!!!!';
    var gcse = document.createElement('script');
    gcse.type = 'text/javascript';
    gcse.async = true;
    gcse.src = 'https://cse.google.com/cse.js?cx='+ cx;
    var s = document.getElementsByTagName('script')[0];
    s.parentNode.insertBefore(gcse, s);
})();

window.onload = function(){
    document.getElementById('gsc-i-id1').placeholder = 'e.g., United Stocks AMD';
};


where cx is a dynamic variable string parameter, defined as the custom search engine ID to use for a request (Custom Search API, ID for custom search).

Result Display Script:

&lt;script&gt;
  (function() {
    var cx = 'partner-pub-1444970657765319:8190375623';
    var gcse = document.createElement('script');
    gcse.type = 'text/javascript';
    gcse.async = true;
    gcse.src = 'https://cse.google.com/cse.js?cx=' + cx;
    var s = document.getElementsByTagName('script')[0];
    s.parentNode.insertBefore(gcse, s);
  })();
&lt;/script&gt;
&lt;gcse:searchresults-only&gt;&lt;/gcse:searchresults-only&gt;


Popular Query Script:

&lt;script type="text/javascript" src="http://www.google.com/cse/query_renderer.js"&gt;&lt;/script&gt;
&lt;div id="queries"&gt;&lt;/div&gt;
&lt;script src="http://www.google.com/cse/api/partner-pub-1444970657765319/cse/8190375623/queries/js?oe=UTF-8&amp;amp;callback=(new+PopularQueryRenderer(document.getElementById(%22queries%22))).render"&gt;&lt;/script&gt;


Added CSS:

/*google custom search*/
.cse .gsc-search-button input.gsc-search-button-v2,input.gsc-search-button-v2{height:26px!important;margin-top:0!important;min-width:13px!important;padding:5px 26px!important;width:68px!important}
.cse .gsc-search-button-v2,.gsc-search-button-v2{box-sizing:content-box;min-width:13px!important;min-height:16px!important;cursor:pointer;border-radius:20px}
.gsc-search-button-v2 svg{vertical-align:middle}
.gs-title{line-height:normal!important}
.gsc-search-box-tools .gsc-search-box .gsc-input{padding:5px!important;color:#4169E1!important;border-radius:20px}
.gsc-input-box{background:none!important;border:none!important}


Screenshot Before Search:



Screenshot After Search:



Screenshot for "Code Review" search:
So after testing it,  you don't really need to define it in your javascript. You can simply add it in your HTML before all your other scripts.

That's what s.parentNode.insertBefore(gcse, s); does. It finds the first occurence of a script tag in your HTML (which is kind of funny as it won't work if there are no script tags in your HTML), and adds your new script before it.

So if the first occurence of a script tag appears in the HEAD, then it'll be placed in the head'



&lt;script src="https://cse.google.com/cse.js?cx=017643444788069204610:4gvhea_mvga" async type="text/javascript"&gt;&lt;/script&gt;
&lt;gcse:search&gt;&lt;/gcse:search&gt;




Making your javascript more efficient will be difficult as 1. there isn't much happening and 2. it's already very short.

But you could do something like this (which doesn't change much)... 

// google search placeholder
(function(cx) {   
    const gcse = document.createElement('script');
    gcse.type = 'text/javascript';
    gcse.async = true;
    gcse.src = `https://cse.google.com/cse.js?cx=${cx}`;
    const s = document.getElementsByTagName('script')[0];
    s.parentNode.insertBefore(gcse, s);
})('!!!!!!!!!!!!!!!!!!!');