1. #1
    Sencha Premium Member
    Join Date
    Apr 2012
    Location
    Germany
    Posts
    27
    Vote Rating
    1
    hebr3 is on a distinguished road

      0  

    Default 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

  2. #2
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    36,754
    Vote Rating
    827
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      0  

    Default


    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
    ________________
    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 in print!

    When posting code, please use BBCode's CODE tags.

  3. #3
    Sencha Premium Member
    Join Date
    Apr 2012
    Location
    Germany
    Posts
    27
    Vote Rating
    1
    hebr3 is on a distinguished road

      0  

    Default


    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.

  4. #4
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    36,754
    Vote Rating
    827
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      0  

    Default


    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
    ________________
    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 in print!

    When posting code, please use BBCode's CODE tags.

  5. #5
    Sencha User
    Join Date
    Sep 2012
    Posts
    5
    Vote Rating
    0
    hguillermo is on a distinguished road

      0  

    Default 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.

  6. #6
    Sencha User
    Join Date
    Sep 2012
    Posts
    3
    Vote Rating
    2
    2p0thunder is on a distinguished road

      1  

    Default


    Quote Originally Posted by hguillermo View Post
    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.
    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:
    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"
            
    }
        ],
    ... 
    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.

    Cheers

  7. #7
    Sencha User
    Join Date
    Sep 2012
    Posts
    5
    Vote Rating
    0
    hguillermo is on a distinguished road

      0  

    Default


    The perfect thing would be if Sencha minifies and concatenates all the js files in one big file. In theory it should do it but it doesn't. However, it does a nice job minifying/concatenating all the css files in one file.

    Can somebody from Sencha confirm this? I noticed Sencha build is minifying all the js files. I though part of the build is concatenate all of those too.

  8. #8
    Sencha User
    Join Date
    Nov 2012
    Posts
    9
    Vote Rating
    0
    pixelated is on a distinguished road

      0  

    Default


    I can confirm that this is indeed the case.

    External libraries (non-sencha related such as JavaScripTools on sourceforge) will only be seen by the app in development and testing modes.

    In production, the files are loaded but cannot be seen from within the sencha app.

    A work-around is to explicitly include the external libraries via script tags in the index.html file. However, is not ideal.

    Can we have some direction as to how to do or not to do this?

    Thanks,

    Ian

  9. #9
    Sencha Premium Member
    Join Date
    Feb 2012
    Location
    Berne, Switzerland
    Posts
    714
    Vote Rating
    42
    ingo.hefti has a spectacular aura about ingo.hefti has a spectacular aura about ingo.hefti has a spectacular aura about

      0  

    Default


    Hmm... I just included an external library and it is working fine when I build my native app (Android). By external you are talking about a file included in your project? That would be my use case.

    Working with ST2.1rc2 and CMD3.0.0.230

  10. #10
    Sencha User
    Join Date
    Sep 2012
    Posts
    5
    Vote Rating
    0
    hguillermo is on a distinguished road

      0  

    Default


    Maybe because you are using the sencha 3.x and building a native app. I am using the Sencha 2.x command and building a web app.

    I am going to try the Sencha command 3.x....

    Thanks