FRIHOSTFORUMSFAQTOSBLOGSDIRECTORY
You are invited to Log in or Register a Frihost Account!

How to programming javascript in one lines ?

 


Philip
I see there is a way to programming javascripts in one lines,
i need to way what have i take a look before make it one lines ?

please someone suggest me,

thanks,
smartbei
I don't wuite understand what you mean, but if you mean to program javascript in one line that is perfectly possible. all you need to do is not use the tab or enter button at all. As long as everything is syntacticaly correct it will work.

Still, it is really hard to read such JavaScript, so I recommend programming it normally and later compressing it.
Stubru Freak
You just program your javascript normally, making sure to end every line with a semi-colon. (Where a semi-colon is appropriate.)
Next, you have two options:
Press end, delete, end, delete, end, delete untill all your code is on 1 line.
Do a regular expression delete (eg. replace by nothing) for [\r\n]* (or [\r\n\t]*)
rohan2kool
as i assume.. i think u wanna do some obfuscation in ur js.
Philip
i created a long2x and big javascript about 38 Kb, i already compressed it with w3compiler, but it seem the script cannot be loaded because some error.*there is no error messages, i knowed it from my AJAX didn;t work.*

i already add semi colon every end of lines, and how about tag comment ?

/* */ <- need to add a semicolon also ??
Stubru Freak
Philip wrote:
i created a long2x and big javascript about 38 Kb, i already compressed it with w3compiler, but it seem the script cannot be loaded because some error.*there is no error messages, i knowed it from my AJAX didn;t work.*

i already add semi colon every end of lines, and how about tag comment ?

/* */ <- need to add a semicolon also ??


You don't have to put a semicolon on every line, only where appropriate.
And make sure you don't use this style of comments:

Code:
Code 1
// Comment
Code 2


As that will result in:

Code:
Code 1 // Comment Code 2


So the Code 2 will also be commented out
Philip
i still dont get, still had the error after compress the javascript files,
how about if syntax ?

is it right syntax ?

Code:
if(a==b)
{
a=true;
}
else
{
a=false;
}
Stubru Freak
Philip wrote:
i still dont get, still had the error after compress the javascript files,
how about if syntax ?

is it right syntax ?

Code:
if(a==b)
{
a=true;
}
else
{
a=false;
}


Yes it is.

If you compress it to:

Code:
if(a==b){a=true;}else{a=false;}


it will work
Philip
how about using ' and " tag for containing string for variable ?
htmlrules
I dont quite get what your saying but if your trying to make it neater and your code shorter have you considered using an external javascript file.
[url]<script type="text/javascript" src="externalfiles/js/1formcheck.js"></script>[/url]
that would load an external javascript file one thing though do not add the

[url]<script></script>[/url] tags to the file or itll screw up[/url]
Reply to topic    Frihost Forum Index -> Scripting -> Html, CSS and Javascript

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2007 Frihost, forums powered by phpBB.