Javascript -如何加载Javascript库,而使用谷歌应用引擎

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

本文关键字:Javascript 谷歌 引擎 应用 何加载 加载      更新时间:2023-09-26

我正在运行谷歌应用程序引擎与Python, yaml。现在我需要使用哪个浏览器也使用PHP和发生的错误是在

但是当我试图加载http://whichbrowser.net/的Javascript库时,它的失败"Uncaught SyntaxError: Unexpected token <"在detect.js第1行:

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:

  (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:

- url: /whichbrowser
  static_dir: whichbrowser

App Engine上加载JavaScript的方式没有什么特别的。它的加载方式和在其他平台/服务器上一样

您的JS文件包含PHP处理指令。如果您的应用程序是用python编写的,则此操作将失败。

你可以在PHPPython中编写应用程序。不能在同一版本中混合使用两种语言。

理论上,你可以使用模块/版本来实现PHPPython版本,并使用调度路由将它们连接在一起,但我认为,如果你只是找到一个没有PHP语言依赖的浏览器检测库,它会简单得多。

关于模块和调度路由的更多信息:链接

仅供参考- Google App Engine -不允许PHP + Python同时运行。为此,您需要使用在另一个服务器上运行的PHP的URL。

这是一个真正的谷歌应用程序引擎陷阱,因为当应用程序变得更大,然后没有办法移动。