NimbleKit - fast iOS app development

External JS File

Ask questions and share your skills here

External JS File

Postby purplespider » Sun May 31, 2009 12:26 am

Is it possible to put all my JavaScript into an external file, rather than have multiple copies of the code in each HTML file?

I have tried creating a main.js file in the "Resources" group, and then added
Code: Select all
<script type="text/javascript" src="main.js"></script>
into the head of my HTML files, just as it has been done with NKit.js, but it doesn't work. It fails to see the Javascript, and when running the App in the simulator, I get the following warning in the Build Results window:
Code: Select all
warning: no rule to process file '$(PROJECT_DIR)/main.js' of type sourcecode.javascript for architecture i386

Am I missing something?

Cheers
James
purplespider
 
Posts: 3
Joined: Sun May 31, 2009 12:20 am

Re: External JS File

Postby sunny » Sun May 31, 2009 10:14 am

The problem here is that when you add javascript file in your project Xcode treats it as a source code file but can not process it, so the file is just ignored, to make it work you have to manually specify that this javascript file is resource.
To do this collapse disclosure trieangle "Targets"->"YOUR_PROJECT_NAME"->Compile Sources and remove your js file from it.
then drag your js file to "Targets"->"YOUR_PROJECT_NAME"->Copy Bundle Resources
User avatar
sunny
Staff
 
Posts: 2666
Joined: Sat May 30, 2009 5:18 am
Location: Palo Alto, California

Re: External JS File

Postby purplespider » Sun May 31, 2009 11:35 am

That worked great, thank you very much!
purplespider
 
Posts: 3
Joined: Sun May 31, 2009 12:20 am

Re: External JS File

Postby Andy Baird » Mon Jun 01, 2009 9:56 pm

This technique also allows the use of external CSS (stylesheet) files, which can greatly simplify page coding as well as reducing overall app size.

Andy Baird
Andy Baird
User avatar
Andy Baird
 
Posts: 113
Joined: Sat May 30, 2009 10:32 pm
Location: On the road in the southwestern US

Re: External JS File

Postby tkambler » Tue Sep 29, 2009 3:08 am

Could anyone provide some additional insight into this? I know this sounds simple, but I have tried for the past 45 minutes to get this to work with no luck.
tkambler
 
Posts: 2
Joined: Tue Sep 29, 2009 3:07 am

Re: External JS File

Postby tkambler » Tue Sep 29, 2009 3:16 am

tkambler wrote:Could anyone provide some additional insight into this? I know this sounds simple, but I have tried for the past 45 minutes to get this to work with no luck.


OK, scratch that. I did finally manage to get my external JS file to load. Weird thing, though... In my JS file, I have the following:

alert('1');

Just as a test. But when I run the iPhone simulator, all I get is dim screen and the app never loads.
tkambler
 
Posts: 2
Joined: Tue Sep 29, 2009 3:07 am

Re: External JS File

Postby sunny » Tue Sep 29, 2009 4:54 am

send the project to support@nimblekit.com I will take a look if you still have problem
User avatar
sunny
Staff
 
Posts: 2666
Joined: Sat May 30, 2009 5:18 am
Location: Palo Alto, California

Re: External JS File

Postby Quast77 » Mon May 16, 2011 9:05 pm

Hi there,

i am sorry and i do not understand how to do this... Can anybody explain it more detailed ?

Thanks
Quast
Thanks and regards,
Quast
User avatar
Quast77
 
Posts: 53
Joined: Sat Apr 09, 2011 4:57 pm
Location: Germany

Re: External JS File

Postby Quast77 » Mon May 16, 2011 9:31 pm

I found the setting in "Targets" and i added my js-File, but it doesn't work. Question: Do i have to enter the path to the file or just the file in my

<script type="text/javascript" src="../javascript/main.js"></script>


??

I have a Javascript-Folder in my project .

Thanks,
Quast
Thanks and regards,
Quast
User avatar
Quast77
 
Posts: 53
Joined: Sat Apr 09, 2011 4:57 pm
Location: Germany

Re: External JS File

Postby Big-O » Mon May 16, 2011 9:56 pm

Quast77 wrote:I found the setting in "Targets" and i added my js-File, but it doesn't work. Question: Do i have to enter the path to the file or just the file in my

<script type="text/javascript" src="../javascript/main.js"></script>


??

I have a Javascript-Folder in my project .

Thanks,
Quast


You might have the path wrong. Depending on how you created the folders they might be 'virtual' meaning that they just look like folders in the tree but aren't actually in folders. Try just linking to the file name instead of adding the rest of the path.
-- Big-O
-- Nimblekit Guru, Web Developer, Hopeless Geek

I do freelance!
http://realisticweb.com
User avatar
Big-O
NimbleKit Guru
 
Posts: 1231
Joined: Thu Sep 24, 2009 4:02 am

Next

Return to How To...

Who is online

Users browsing this forum: Google [Bot] and 1 guest