SitePoint Sponsor |
|
User Tag List
Results 1 to 4 of 4
-
May 1, 2007, 14:04 #1
- Join Date
- Jan 2007
- Location
- Orlando, FL
- Posts
- 417
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Is this possible? php creating a .js file and then including it in the same page
Basically the question is when does an included .js script file get read? Is it after the server is done processing php? Is it requested by the browser or the server?
Basically what I am looking to do is make a bunch of database information available to javascript in the form of arrays. These arrays would be defined by php while the server is making the html file. If this script was all inline it would make copying and pasting all that data easy for anyone else, and I would rather not give away all that info.
So I thought I could have php access the database, make a something.js file with all the array declarations, and then include that file instead. Would that obfuscate the values? Would it even work?
-
May 1, 2007, 14:12 #2
- Join Date
- Mar 2005
- Location
- USA
- Posts
- 5,482
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
The browser requests the .js file when it encounters the <script> element that links to it. (This assumes JavaScript support is enabled.)
No, linking to an external script does not hide information. If you want to hide it, then perhaps you should use AJAX.We miss you, Dan Schulz.
Learn CSS. | X/HTML Validator | CSS validator
Dynamic Site Solutions
Code for Firefox, Chrome, Safari, & Opera, then add fixes for IE, not vice versa.
-
May 1, 2007, 15:00 #3
- Join Date
- Jan 2007
- Location
- Orlando, FL
- Posts
- 417
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Yeah, I guess I wasn't thinking very clearly. Of course nothing javascript does is hidden.
Not a big deal. I'm just in a weird paranoid mood today ;P
Thanks for the info, at least I know I can do it either with an include or with the script right in the html. Not sure if there are any real benefits to doing one over the other.
-
May 1, 2007, 15:39 #4
- Join Date
- Mar 2005
- Location
- USA
- Posts
- 5,482
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
If the information doesn't change very often, using an external script can benefit from caching.
We miss you, Dan Schulz.
Learn CSS. | X/HTML Validator | CSS validator
Dynamic Site Solutions
Code for Firefox, Chrome, Safari, & Opera, then add fixes for IE, not vice versa.
Bookmarks