Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Load JavaScript in Google App Engine

I got so confused loading JavaScript in Google App Engine. I am using the Django template.

First, in my base HTML file, I can't load my downloaded jQuery code from local say, d:/jquery.js, like

<script src="d:\jquery.js" type="text/javascript" ></script></head>,

This line is in my base HTML file. It works when I load jQuery from remote. Like

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"type="text/javascript" ></script></head>

I don't know why.

Second, I can't load my own-created JavaScript code to my HTML file. Say I create a JavaScript file, like layout.js, and I try to load it like this in my child HTML file, which, by the way, inherits from the base HTML.

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

And it doesn't work at all. The only way it works I have tried is when I put the actual JavaScript code in the body of my base HTML file. Like

<body><script>
    $(document).ready(
        $("#yes").click(function() {
            $("#no").hide("slow");
    }));
</script>

I don't know why either... How do I fix it?

like image 404
Clinteney Hui Avatar asked Mar 12 '11 15:03

Clinteney Hui


1 Answers

AppEngine doesn't know anything about paths on your local system; it will only upload files that you configure it to. Do this by having a line like this in your app.yaml file:

handlers:
- url: /js
  static_dir: js

In this case, /js represents a subdirectory of your main project directory, and you can put all of your static JavaScript files in there. They will be uploaded to the production server, and you can include them in your HTML with:

<script src="/js/jquery.js" type="text/javascript" ></script>
like image 157
Adam Crossland Avatar answered Oct 15 '22 09:10

Adam Crossland