3

I want to put a minified java script contents in tags directly in HTML page. i have html page like:

<html>
  <head>
      <script src="jquery.js"></script>
      <script src="iemagic.js"></script>
      <script src="shim.js"></script>
      <script src="jszip.js"></script>
      <script src="xlsx.js"></script>
  </head>
</html>

I have minified all the javascript contents and put it in a single file called "all.js" and the html works fine, now it looks like :

<html>
  <head>
      <script src="all.js"></script>
  </head>
</html>

I want to include all the content of "all.js" in to HTML directly in "script" tag. I tried with that but no luck, when i open html file in browser it show all the java script content which i have copied in "script" tag.

Is there any other way for this ?

user3515080
  • 545
  • 2
  • 6
  • 17
  • do you want this to be automated or manual ? – Venkat.R Sep 30 '16 at 06:17
  • There are such build tools like [Gulp](http://gulpjs.com/) or [Bower](https://bower.io/) out there. You might want to check them out. – choz Sep 30 '16 at 06:19
  • Thank you all, i too heard that "Gulp and Bower" will do, but i want to know the steps to do that. @Venkatraman - anything, i just want remove all "js" files and there should be only one HTML file. – user3515080 Sep 30 '16 at 06:23
  • Putting all the content – HTML, scripts and CSS – into a single .html file will usually decrease the loading speed of your page. Don't do that. – Teemu Sep 30 '16 at 06:35
  • @Teemu, Thank you for you suggestion. But i need to know the way. – user3515080 Sep 30 '16 at 06:41
  • @KrupeshKotecha - Thank you for formatting the code. – user3515080 Sep 30 '16 at 10:01
  • " I tried with that but no luck, when i open html file in browser it show all the java script content which i have copied in "script" tag." — Either something is wrong with the way you did that *or* something about the script itself is responsible for that … either way, you need to provide a [MCVE] that **demonstrates the problem**. – Quentin Sep 30 '16 at 10:22

2 Answers2

2

Thank you all for helping me. i have found the solution for this. * added all the "js" files in different "script" tag tested working fine but some of the javascript lines was visible in the browswer. * The problem was "iemagic.js" was having the comments which are not proper and was creating the problem. * I have removed those commented lines and is working find now. without having any "js" file and only one HTML. Thank you All for your help and valuable time.

user3515080
  • 545
  • 2
  • 6
  • 17
1

You can use gulp or jscompress

Morteza Negahi
  • 3,305
  • 8
  • 24
  • 42
  • i tried this and copied in "all.js", it is working fine. but i want move all the content to HTML page directly in "script" tag. Thank you. – user3515080 Sep 30 '16 at 06:21
  • So you have objects data to that define the content of the page? – Dinca Adrian Sep 30 '16 at 06:23
  • @DincaAdrian - Can you elaborate ? Thanks. – user3515080 Sep 30 '16 at 06:29
  • Do you have scripts and data(articles, products, persons)? compressing files with jscompress will remove the objects and just leave the script it seems...so putting all the data into a JSON file separate will be nice and leave all the logic in all.js. Test Jscompress with document.ready and define a simple object and see what happens. – Dinca Adrian Sep 30 '16 at 06:43
  • @DincaAdrian - I have done this already and it is working. now i want to remove the "all.js" and copy the content of "all.js" in to script tag of the HTML file. – user3515080 Sep 30 '16 at 06:52