简体   繁体   English

Javascript-使用Google App Engine时如何加载JavaScript库?

[英]Javascript - how to load the javascript library while using Google App Engine?

I am running Google App engine with Python, yaml. 我正在使用Python,yaml运行Google App引擎。 Now i need to use whichbrowser.net with it (whichbrowser is using also a PHP and the error that occure is in the 现在我需要使用whichbrowser.net(whichbrowser也使用PHP,并且发生的错误在

But when i am trying to load the Javascript libraries of http://whichbrowser.net/ its failing "Uncaught SyntaxError: Unexpected token < " on detect.js line 1: 但是,当我尝试加载http://whichbrowser.net/的Javascript库时,在detect.js第1行上失败的“ Uncaught SyntaxError:Unexpected token <”失败:

detect.js: detect.js:

<?php

    header("Content-Type: text/javascript");
    header("Cache-Control: no-cache, no-store, must-revalidate, max-age=0"); 
    header("Pragma: no-cache");
    header("Expires: 0"); 

    include('libraries/whichbrowser.php');

    $options = array('headers' => apache_request_headers());
    if (isset($_REQUEST['ua'])) $options['useragent'] = $_REQUEST['ua'];
    if (isset($_REQUEST['e'])) $options['engine'] = intval($_REQUEST['e']);
    if (isset($_REQUEST['f'])) $options['features'] = intval($_REQUEST['f']);
    if (isset($_REQUEST['w'])) $options['width'] = intval($_REQUEST['w']);
    if (isset($_REQUEST['h'])) $options['height'] = intval($_REQUEST['h']);
    $detected = new WhichBrowser($options);

?>

index.html: index.html的:

  (function(){var p=[],w=window,d=document,e=f=0;p.push('ua='+encodeURIComponent(navigator.userAgent));e|=w.ActiveXObject?1:0;e|=w.opera?2:0;e|=w.chrome?4:0;
  e|='getBoxObjectFor' in d || 'mozInnerScreenX' in w?8:0;e|=('WebKitCSSMatrix' in w||'WebKitPoint' in w||'webkitStorageInfo' in w||'webkitURL' in w)?16:0;
  e|=(e&16&&({}.toString).toString().indexOf("\n")===-1)?32:0;p.push('e='+e);f|='sandbox' in d.createElement('iframe')?1:0;f|='WebSocket' in w?2:0;
  f|=w.Worker?4:0;f|=w.applicationCache?8:0;f|=w.history && history.pushState?16:0;f|=d.documentElement.webkitRequestFullScreen?32:0;f|='FileReader' in w?64:0;
  p.push('f='+f);p.push('r='+Math.random().toString(36).substring(7));p.push('w='+screen.width);p.push('h='+screen.height);var s=d.createElement('script');
  s.src='/whichbrowser/detect.js?' + p.join('&');d.getElementsByTagName('head')[0].appendChild(s);})();

app.yaml: app.yaml中:

- url: /whichbrowser
  static_dir: whichbrowser

There is nothing special about the way you load JavaScript on App Engine . App Engine上加载JavaScript的方式没有什么特别的。 It loads the same way as it would on any other platform/server. 它的加载方式与在其他平台/服务器上加载的方式相同。

Your JS file(s) include PHP processing directives. 您的JS文件包含PHP处理指令。 This will fail if your application is written in python. 如果您的应用程序是用python编写的,这将失败。

You can write your app in PHP , or you can write it in Python . 您可以使用PHP编写应用程序,也可以使用Python编写应用程序。 You cannot commingle both languages in the same version. 您不能在同一版本中混合使用两种语言。

You could in theory use modules/versions to implement a PHP and a Python version and use dispatch routing to wire them together, but I'd posit that its far simpler if you simply find a browser detection library that doesn't have the PHP language dependency. 从理论上讲,您可以使用模块/版本来实现PHPPython版本,并使用分派路由将它们连接在一起,但是我认为,如果您只是找到一个没有PHP语言的浏览器检测库,它就容易得多。依赖。

More information about modules and dispatch routing: LINK 有关模块和调度路由的更多信息: LINK

FYI - Google App Engine - do not allow PHP + Python to run at once. 仅供参考-Google App Engine-不允许同时运行PHP + Python。 For that you need to use URL of the PHP running in another server. 为此,您需要使用在另一台服务器上运行的PHP的URL。

This is a really Google App Engine trap, cause when the application become larger then there is no way to move. 这是一个真正的Google App Engine陷阱,导致当应用程序变大时便无法移动。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM