Webmaster Forum


Go Back   Webmaster Forum > Web Development > Coding Forum

Coding Forum Problems with your code? Discuss coding issues, including JavaScript, PHP & MySQL, HTML & CSS, Flash & ActionScript, and more.


Closed Thread
 
LinkBack Thread Tools Display Modes
Share |
  #1 (permalink)  
Old 09-27-2011, 05:52 AM
Banned
 
Join Date: 05-28-11
Location: Around the biggest network around
Posts: 15
iTrader: 0 / 0%
What's the best way to load scripts?

hey, I'm wondering about the best way to load scripts in a normal (php/html) website, I mean, I've this site that has some external scripts, and I've to add all of it to the head section, can I add a call to a file that in that file I can place all the javascipt urls to load:
for example:

HTML Code:
<head> <script type="text/javascript" src="js/website-scripts.js"></script> </head>
and in that js file:

HTML Code:
<script type="text/javascript" src="js/custom.js"></script> <script type="text/javascript" src="js/slides.min.jquery.js"></script> <script type="text/javascript" src="js/nivo-slider/jquery.nivo.slider.pack.js"></script> <script type="text/javascript" src="js/superfish-menu/hoverIntent.js"></script> <script type="text/javascript" src="js/superfish-menu/superfish.js"></script> <script type="text/javascript" src="js/scrolltop/scrolltopcontrol.js"></script> <script type="text/javascript" src="js/prettyPhoto/jquery.prettyPhoto.js"></script> <script type="text/javascript" src="js/jquery.featureList-1.0.0.js"></script> <script type="text/javascript" src="js/swfobject/swfobject.js"></script> <script type="text/javascript" src="js/easing/jquery.easing.1.3.js"></script> <script type="text/javascript" src="js/kwicks/jquery.kwicks-1.5.1.pack.js"></script>

am I dreaming? or can it be done, and if so, is it a good practice?

Last edited by karl1; 09-27-2011 at 06:08 AM.
 
  #2 (permalink)  
Old 09-29-2011, 02:50 AM
JohnnyS's Avatar
Contributing Member
 
Join Date: 07-05-11
Location: philippines
Posts: 312
iTrader: 0 / 0%
Quote:
Originally Posted by karl1 View Post
hey, I'm wondering about the best way to load scripts in a normal (php/html) website, I mean, I've this site that has some external scripts, and I've to add all of it to the head section, can I add a call to a file that in that file I can place all the javascipt urls to load:
for example:

HTML Code:
<head> <script type="text/javascript" src="js/website-scripts.js"></script> </head>
and in that js file:

HTML Code:
<script type="text/javascript" src="js/custom.js"></script> <script type="text/javascript" src="js/slides.min.jquery.js"></script> <script type="text/javascript" src="js/nivo-slider/jquery.nivo.slider.pack.js"></script> <script type="text/javascript" src="js/superfish-menu/hoverIntent.js"></script> <script type="text/javascript" src="js/superfish-menu/superfish.js"></script> <script type="text/javascript" src="js/scrolltop/scrolltopcontrol.js"></script> <script type="text/javascript" src="js/prettyPhoto/jquery.prettyPhoto.js"></script> <script type="text/javascript" src="js/jquery.featureList-1.0.0.js"></script> <script type="text/javascript" src="js/swfobject/swfobject.js"></script> <script type="text/javascript" src="js/easing/jquery.easing.1.3.js"></script> <script type="text/javascript" src="js/kwicks/jquery.kwicks-1.5.1.pack.js"></script>

am I dreaming? or can it be done, and if so, is it a good practice?
http://code.google.com/p/minify/ would be the best answer..
 
  #3 (permalink)  
Old 09-29-2011, 03:21 AM
Banned
 
Join Date: 05-28-11
Location: Around the biggest network around
Posts: 15
iTrader: 0 / 0%
thanks Johnny.
now it makes more sense, even though I needed to know if my doubt was posible or not
 
  #4 (permalink)  
Old 09-29-2011, 06:01 AM
WaNey's Avatar
Member
Latest Blog:
None

 
Join Date: 09-29-11
Posts: 37
iTrader: 0 / 0%
your practise is very intresting, impress me! but I don't know the effectness of such method,hope more people can answer the question..
__________________
come here to get free ebook cover creator| win free ipad 2
 
  #5 (permalink)  
Old 09-29-2011, 04:52 PM
Alexwhin's Avatar
Member
Latest Blog:
None

 
Join Date: 09-29-11
Location: Wales, UK
Posts: 32
iTrader: 0 / 0%
Minify is a great way of getting this done. Also, if you can get the compressed version of the librarys then all the better.
__________________
Bespoke Web Design, Development and Hosting with VantageDesign:
vantagedesign.co.uk or vantagedesign.co.uk/webhosting/
 
  #6 (permalink)  
Old 10-04-2011, 01:53 AM
JohnnyS's Avatar
Contributing Member
 
Join Date: 07-05-11
Location: philippines
Posts: 312
iTrader: 0 / 0%
Quote:
Originally Posted by karl1 View Post
thanks Johnny.
now it makes more sense, even though I needed to know if my doubt was posible or not
you're welcome!
 
  #7 (permalink)  
Old 10-08-2011, 05:26 PM
Rukbat's Avatar
Contributing Member
Latest Blog:
None

 
Join Date: 08-08-11
Location: Long Island, NY, USA
Posts: 287
iTrader: 0 / 0%
PHP Code:
<?php
...
echo 
'<head>';
require(
'js/website-scripts.js');
in website-scripts.js, you have
PHP Code:
echo '<script type="text/javascript" src="js/custom.js"></script>
<script type="text/javascript" src="js/slides.min.jquery.js"></script>
<script type="text/javascript" src="js/nivo-slider/jquery.nivo.slider.pack.js"></script>
<script type="text/javascript" src="js/superfish-menu/hoverIntent.js"></script>
<script type="text/javascript" src="js/superfish-menu/superfish.js"></script>
<script type="text/javascript" src="js/scrolltop/scrolltopcontrol.js"></script>
<script type="text/javascript" src="js/prettyPhoto/jquery.prettyPhoto.js"></script>
<script type="text/javascript" src="js/jquery.featureList-1.0.0.js"></script>
<script type="text/javascript" src="js/swfobject/swfobject.js"></script>
<script type="text/javascript" src="js/easing/jquery.easing.1.3.js"></script>
<script type="text/javascript" src="js/kwicks/jquery.kwicks-1.5.1.pack.js"></script>'

and just add or delete files in website-scripts.js as needed.
 
  #8 (permalink)  
Old 10-24-2011, 06:07 AM
Banned
 
Join Date: 05-28-11
Location: Around the biggest network around
Posts: 15
iTrader: 0 / 0%
@ Rukbat
Why do you have the echo, can I just use the require function?
 
  #9 (permalink)  
Old 10-24-2011, 10:47 AM
Rukbat's Avatar
Contributing Member
Latest Blog:
None

 
Join Date: 08-08-11
Location: Long Island, NY, USA
Posts: 287
iTrader: 0 / 0%
Quote:
Originally Posted by karl1 View Post
@ Rukbat
Why do you have the echo, can I just use the require function?
You wanted it in the head, so you have to have an HTML <head> tag. You can do it either way:

<?php
...
echo '<head>';

or

<head>
<?php

Since my default PHP file includes FirePHP at the top, I have nothing preceding my <?php tag. (That sends headers, and can cause the script to bomb out.)
 
  #10 (permalink)  
Old 10-24-2011, 11:14 AM
Banned
 
Join Date: 05-28-11
Location: Around the biggest network around
Posts: 15
iTrader: 0 / 0%
Quote:
Originally Posted by Rukbat View Post
You wanted it in the head, so you have to have an HTML <head> tag. You can do it either way:

<?php
...
echo '<head>';

or

<head>
<?php

Since my default PHP file includes FirePHP at the top, I have nothing preceding my <?php tag. (That sends headers, and can cause the script to bomb out.)
OK
I'm used to the second one.
Nice tip, thanks for the info
 
  #11 (permalink)  
Old 10-25-2011, 09:38 AM
Banned
 
Join Date: 05-28-11
Location: Around the biggest network around
Posts: 15
iTrader: 0 / 0%
I got a question again, sorry.
Should I use one echo for every css file for example, or can I use
Quote:
<php
echo '<head>
<link href="css/style.css" rel="stylesheet" type="text/css" />
<link href="css/reset.css" rel="stylesheet" type="text/css" />
<link href="css/ie7.css" rel="stylesheet" type="text/css" />';
?>
what about the body, is it OK to leave it outside php tags?
thanks
 
Go Back   Webmaster Forum > Web Development > Coding Forum

Closed Thread


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Normal load only have 200+ tasks, but sometime suddenly get High load with 500+ tasks basketmen Web Hosting Forum 1 10-29-2010 12:16 AM
WTS: ScriptGeni Money Maker Scripts DISCOUNT! - Get 3 Scripts for the price of 2 vidal Content 0 03-17-2010 06:46 AM
SEO Scripts 2.0 - 77 SEO Scripts - Save 20% for a Limited Time Tekime Content 2 09-19-2009 03:59 PM
SEO Scripts 2.0 - 77 SEO Scripts - Save 25% for a Limited Time Tekime Content 0 06-15-2009 12:51 AM


V7N Network
Get exposure! V7N I Love Photography V7N SEO Blog V7N Directory


All times are GMT -7. The time now is 03:20 PM.
Powered by vBulletin
Copyright © 2000-2013 Jelsoft Enterprises Limited.
Copyright © 2003 - 2013 Escalate Media LP




Search Engine Optimization by vBSEO 3.6.0 RC 2 ©2011, Crawlability, Inc.