簡體   English   中英

Javascript-使用Google App Engine時如何加載JavaScript庫?

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

我正在使用Python,yaml運行Google App引擎。 現在我需要使用whichbrowser.net(whichbrowser也使用PHP,並且發生的錯誤在

但是,當我嘗試加載http://whichbrowser.net/的Javascript庫時,在detect.js第1行上失敗的“ Uncaught SyntaxError:Unexpected token <”失敗:

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編寫的,這將失敗。

您可以使用PHP編寫應用程序,也可以使用Python編寫應用程序。 您不能在同一版本中混合使用兩種語言。

從理論上講,您可以使用模塊/版本來實現PHPPython版本,並使用分派路由將它們連接在一起,但是我認為,如果您只是找到一個沒有PHP語言的瀏覽器檢測庫,它就容易得多。依賴。

有關模塊和調度路由的更多信息: LINK

僅供參考-Google App Engine-不允許同時運行PHP + Python。 為此,您需要使用在另一台服務器上運行的PHP的URL。

這是一個真正的Google App Engine陷阱,導致當應用程序變大時便無法移動。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM