Need to put js into external file

Discussion in 'HTML & Website Design' started by jazzzyman, Mar 10, 2013.

  1. #1
    In an effort to reduce my sites loading time i want to put java script code in external files to get them to load up quicker

    how do i put the code in a file and still get the code to load up in the same place on the page?
    also how do i rearrange the order thing on the page load?

    i know very little about coding and need to do this in html
     
    jazzzyman, Mar 10, 2013 IP
  2. qwikad.com

    qwikad.com Illustrious Member Affiliate Manager

    Messages:
    7,293
    Likes Received:
    1,699
    Best Answers:
    31
    Trophy Points:
    475
    #2
    You create a file first, name it something like: myfile.js

    Then copy your js code and paste it into myfile.js then save it.

    Next remove the js code from the page, and instead put this link between

    <head> </head> in your site's header:

    <script type="text/javascript" src="myfile.js"></script>
    Code (markup):
    That should work.
     
    Last edited: Mar 10, 2013
    qwikad.com, Mar 10, 2013 IP
  3. qwikad.com

    qwikad.com Illustrious Member Affiliate Manager

    Messages:
    7,293
    Likes Received:
    1,699
    Best Answers:
    31
    Trophy Points:
    475
    #3
    By the way you don't need to copy this in your old code:

    <script type="text/javascript">

    </script>

    Copy only what is between those tags.
     
    qwikad.com, Mar 10, 2013 IP
  4. AlbCoder

    AlbCoder Well-Known Member

    Messages:
    126
    Likes Received:
    1
    Best Answers:
    1
    Trophy Points:
    163
    #4
    I cant undertand exactly what do you wnt?can you explain it more,wich is ur page and more...
     
    AlbCoder, Mar 10, 2013 IP
  5. jazzzyman

    jazzzyman Well-Known Member

    Messages:
    117
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    103
    #5
    still a bit confused
     
    jazzzyman, Mar 10, 2013 IP
  6. jazzzyman

    jazzzyman Well-Known Member

    Messages:
    117
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    103
    #6
    i have addthis, adsense and other java on my page

    i want to put the code into a file to make the page load faster but still have the visual elements of the code (adsense) for example load up in the original position on the page
     
    jazzzyman, Mar 10, 2013 IP
  7. AlbCoder

    AlbCoder Well-Known Member

    Messages:
    126
    Likes Received:
    1
    Best Answers:
    1
    Trophy Points:
    163
    #7
    if you paste these codes in external files that wont make your page faster.
    anyway if I'm not wrong you can do that by changing your html page file to .php format and use this command;
    <?php include 'yourexternalfile.txt'; ?>
    Code (markup):
     
    AlbCoder, Mar 10, 2013 IP
  8. jazzzyman

    jazzzyman Well-Known Member

    Messages:
    117
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    103
    #8
    i cant change the page to php or it will lose its inbound links
    say i have a file with 5 sets of javascript in it, how do i reference a specific script out of it onto the position on the page
     
    jazzzyman, Mar 10, 2013 IP
  9. jazzzyman

    jazzzyman Well-Known Member

    Messages:
    117
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    103
    #9
    anyone?
     
    jazzzyman, Mar 12, 2013 IP
  10. deathshadow

    deathshadow Acclaimed Member

    Messages:
    9,732
    Likes Received:
    1,999
    Best Answers:
    253
    Trophy Points:
    515
    #10
    That makes no sense whatsoever... changing what the PHP file is generated won't change it's location, so how would that effect inbound?

    Really I think you need to show us the page in question, though I get the feeling you don't know enough about HTML or PHP (or english) for any explanation we give you to make sense to you -- since to be frank none of your posts make any sense to us.

    I mean, qwikad put it about as plainly and simply as it gets -- there is no "simpler" explanation!
     
    deathshadow, Mar 12, 2013 IP