Hybrid View
-
29 May 2012 11:35 PM #1
How to include my own javascript files
How to include my own javascript files
Hi,
I want to include my own javascript file into a sencha touch project (having some global constants etc.). To do so I just created the file in the app directory and used in the index.html a
<script type="text/javascript" src="app/filename.js"></script>
This works fine with localhost.
However, as soon as I build a production build and deploy it, I get the error
GET http:/..../myapp/app/filename.js 404 (not found)
--> the build does not get the file automatically
What is the right way of adding my own js-files, so that they automatically become part of the build and are cached on the mobile device?
Thanks, hebr3
-
31 May 2012 11:41 AM #2Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 33,648
- Vote Rating
- 434
If you created your app with Sencha Command then you should not edit index.html. Instead you should add JS files to the js property of app.json.
Mitchell Simoens @SenchaMitch
Sencha Inc, Senior Forum Manager
________________
http://www.JSONPLint.com - Source to lint your JSONP!
Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
https://github.com/mitchellsimoens
Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/
Need more help with your app? Hire Sencha Services services@sencha.com
Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is almost in print!
When posting code, please use BBCode's CODE tags.
-
2 Jun 2012 5:06 AM #3
I added the files to app.json and indeed, now they get deployed.
However, if I add the files not to index.html, I get an error in the code referencing to the global variable in one of my files. It seem that in this case I have to add them to index.html.
-
12 Jul 2012 4:40 AM #4Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 33,648
- Vote Rating
- 434
If you add it to the js array it won't be included? It won't be put into index.html it will be loaded via an ajax call when you launch the production build.
Mitchell Simoens @SenchaMitch
Sencha Inc, Senior Forum Manager
________________
http://www.JSONPLint.com - Source to lint your JSONP!
Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
https://github.com/mitchellsimoens
Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/
Need more help with your app? Hire Sencha Services services@sencha.com
Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is almost in print!
When posting code, please use BBCode's CODE tags.
-
22 Oct 2012 2:58 PM #5
It is not working in production mode
It is not working in production mode
Hi guys,
I added the js files in the app.json file and it works in development mode. After I created the production mode using the sencha command it doesn't work. The files are not loaded. Is this a bug? I though all files were minified and concatenated in the app.js file.
-
30 Oct 2012 5:32 AM #6
I can confirm this behaviour, as I am currently having similar problem. I am loading a config.js file with microloader as specified in the app.json. However, the app, while in production mode, complains that the variables from this file are not defined. When I check my localstorage in the Chrome's resources tab, I can see that the config.js file is loaded, but it is loaded last, that is after the app.js, so I figure it is the reason why the app does not really know about the included file.
I managed to make it working by setting the 'remote' option in app.json to true, like so:
However I take this as a workaround and I would be grateful if someone could advise on how to include the config.js file not as remote and as the first one, so that it can be used for settings in the app.PHP Code:...
"js": [
{
"path": "resources/js/config.js",
"remote": true
},
{
"path": "touch/sencha-touch.js"
},
{
"path": "app.js",
"bundle": true, /* Indicates that all class dependencies are concatenated into this file when build */
"update": "delta"
}
],
...
Cheers


Reply With Quote