Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

make require work in dev mode with phantomjs

  • Loading branch information...
commit 60a2bdac97f655b9e87aa859a47321be5e3c2f50 1 parent 9f42e92
@marcuswestin authored
Showing with 8 additions and 4 deletions.
  1. +8 −4 server.js
View
12 server.js
@@ -100,9 +100,11 @@ function _handleMainModuleRequest(reqPath, req, res) {
var response = ['__require__ = {}', 'require=function(){}']
- var userAgent = req.headers['user-agent'],
- isMobile = userAgent.match('iPad') || userAgent.match('iPod') || userAgent.match('iPhone') || userAgent.match('Android')
-
+ var userAgent = req.headers['user-agent']
+ var isMobile = userAgent.match('iPad') || userAgent.match('iPod') || userAgent.match('iPhone') || userAgent.match('Android')
+ var isPhantom = userAgent.match(/PhantomJS/)
+
+
if (isMobile) {
// mobile clients take too long per js file request. Inline all the JS into a single request
for (var i=0, dependency; dependency = deps[i]; i++) {
@@ -115,7 +117,9 @@ function _handleMainModuleRequest(reqPath, req, res) {
' var src = __require__.__scripts.shift()',
' var url = location.protocol+"//"+location.host + src',
' if (!src) { return }',
- ' document.getElementsByTagName("head")[0].appendChild(document.createElement("script")).src = url',
+ isPhantom ? ' setTimeout(function() {' : '',
+ ' document.getElementsByTagName("head")[0].appendChild(document.createElement("script")).src = url',
+ isPhantom ? ' }, 20)' : '',
'}')
for (var i=0, dependency; dependency = deps[i]; i++) {
Please sign in to comment.
Something went wrong with that request. Please try again.