search

Home  >  Q&A  >  body text

How to merge javascript - Stack Overflow

Two customers gave two pieces of code:

First paragraph:

<script id='_bdhm_mkt_2d221'>
(function() {
var mkt = document.createElement('script');
mkt.src = '//click.hm. baidu.com/mkt.js?2d221';
var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(mkt, s);
})() ;
</script>

Second paragraph:
<script src="https://ajax.googleapis.com/a...

How to package it into a new js? That is, a js contains the above two pieces of code?

曾经蜡笔没有小新曾经蜡笔没有小新2708 days ago903

reply all(2)I'll reply

  • 仅有的幸福

    仅有的幸福2017-07-05 11:08:36

    1. Open Notepad and paste in the first piece of code.

    2. Open Google’s JS code link, copy and paste the entire content into Notepad after the first piece of code.

    3. Save the new file as a new JS, link to the page, Done!

    Of course, you cannot do this when the content of the second script changes dynamically.
    If you think it’s low, you can look at Gulp or Webpack.

    reply
    0
  • 仅有的幸福

    仅有的幸福2017-07-05 11:08:36

    webpack, you deserve it~. webpack2 guide

    reply
    0
  • Cancelreply