 		script = document.createElement 'script'
 		script.src = ASSET_EI_JS_URL
 		script.async = true
-		@$context.append script
+		script.insertBefore
+		@$context.before script
 
 	initCodePenJS: ->
-		if typeof CodePenEmbed isnt 'object'
-			@injectCodePenJS() # CodePenEmbed will auto-execute after appended
-		else
+		scriptSelector = 'script[src="' + ASSET_EI_JS_URL + '"]'
+		isCodePenJSInjected = ($(scriptSelector).length > 0)
+		if isCodePenJSInjected isnt true
+			# Note: CodePenEmbed will auto-execute
+			# after it's loaded (ei.js)
+			@injectCodePenJS()
+		else if typeof CodePenEmbed is 'object'
 			CodePenEmbed.init()
 
 	getTemplate: (params) ->

		watcher.destroy() if watcher isnt null

	injectCodePenMarkup: =>
		slug = @$context.data DATA_SLUG

		if slug?
			height = @getHeight()
			tmpl = @getTemplate height: height, slug: slug

			@$context.append tmpl

			setTimeout =>
				@initCodePenJS()


	getHeight: ->
		ratio = @getRatio()
		HEIGHT * ratio

	getSlug: ->
		@$context.data DATA_SLUG

	getRatio: ->
		ratio = @$context.data DATA_RATIO
		return if ratio then parseInt(ratio, 10) else 1