Farhadi said:
before, I had included my js files thruogh Script block at the HEAD.
now I want to include them using XMLHTTPRequest because of 2 reason:
1. I want to load scripts on onload event of body. to speed up loading
of page.
Then use an onload event to load the scripts by adding script elements
with src attributes that link the files.
But your intention seems misguided, unless the scripts are really huge
(by script standards, say more than 50KB) then they will have little or
no effect on the time taken to load the page (assuming a non-trivial
site).
2. I dont want my scripts be saveable thruogh "Save As" at browser.
Presuming XMLHttpRequest will prevent that (and even if it does, how
long will it last?) what is the point? It will not prevent
knowledgeable users from creating their own local copies of your script
files should they wish.
If your scripts are worth copying, anyone defeated by XMLHttpRequest or
other means will likely not have a use for them anyway. Those who know
how to get around your defences will - your scripts will be in the
hands of those who may (if my guessing of your thoughts is correct)
best benefit from them.
In my experience such users find it easier and faster to write their
own scripts, particularly if they are to be used on a site with any
kind of quality control system.
and I want to run my script just like including them on a script block.
is there any more ways?
Then do that. There are utilities to minify code, some of which result
in sufficient obfuscation that the effort required to de-mystify the
code makes it not worth while (though I would never suggest that as a
sole criterion for minification, it may be considered a useful
side-effect by some).
<URL:
http://www.crockford.com/javascript/jsmin.html>