pdf.js使用web workers:
<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>但据我所知,web工作人员不能访问来自javascript文件的url以外的任何内容:
Can I load a web worker script from an absolute URL?
我在亚马逊EC2上托管我的网站,但在亚马逊S3上提供静态文件。
因此,当我尝试运行等效行: PDFJS.workerSrc =‘../../src/worker_loader.js’时,我得到了一个错误:.js无法加载。
我是否正确地理解了这个问题,如果是这样,我有什么选择来解决这个问题?
发布于 2013-02-15 15:39:20
似乎有两种可能的方法。或者关闭工作进程:
从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所建议的,在与Django相同的Apache VirtualHost上提供pdf.js是相对容易的,其中一些文件由URL作为静态媒体提供,而其他文件则使用到Django的mod_wsgi接口。对于apache部署,文档here相对容易遵循。对于本地开发,添加到urls.py中的以下snippet很容易适应为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,
}),
)在settings.py中适当设置了MEDIA_URL和MEDIA_ROOT
两者都会对性能产生影响。
https://stackoverflow.com/questions/14860667
复制相似问题