2013-02-13 59 views
0

pdf.js使用網絡工作者:pdf.js和Django的

<script type="text/javascript"> 
    // Specify the main script used to create a new PDF.JS web worker. 
    // In production, change this to point to the combined `pdf.js` file. 
    PDFJS.workerSrc = '../../src/worker_loader.js'; 
</script> 

,但據我瞭解網絡工作者不能說的JavaScript文件來自的URL外部訪問任何內容:

Can I load a web worker script from an absolute URL?

我在AWS EC2上託管我的網站,但是從AWS S3提供靜態文件。

因此,當我試圖運行這行代碼時,我得到一個錯誤:PDFJS.workerSrc ='../../src/worker_loader.js'; .js無法加載。

我是否正確地理解了這個問題,如果有的話,我有什麼方法可以解決這個問題?

+1

什麼阻止您在同一網站上託管pdf.js文件? – async5 2013-02-14 01:07:46

+0

我想爲aws s3提供大部分靜態文件 - 是否可以只使用與主django應用程序相同的服務器的pdf.js文件,並將剩餘的s3文件保留在其中? – 2013-02-14 08:39:27

回答

1

似乎有兩種可能的方法。無論是關閉的工人:

從pdf.js example

// Disable workers to avoid yet another cross-origin issue (workers 
// need the URL of // the script to be loaded, and currently do not allow 
// cross-origin scripts) 
// PDFJS.disableWorker = true; 

或由async5相對容易供職於同一個Apache虛擬主機作爲Django的pdf.js,有一些文件提供建議通過URLs作爲靜態媒體,以及其他使用mod_wsgi接口的Django。文檔here相對容易遵循apache部署。對於地方發展snippet加入的urls.py以下是容易適應服務了pdf.js:

from django.conf import settings 

# ... the rest of your URLconf goes here ... 

if settings.DEBUG: 
    urlpatterns += patterns('', 
     url(r'^media/(?P<path>.*)$', 'django.views.static.serve', { 
      'document_root': settings.MEDIA_ROOT, 
     }), 
    ) 

與MEDIA_URL和MEDIA_ROOT適當設定settings.py

雙方將有性能問題。