How to create a Shopify application that inserts a JavaScript file?

Recently, I started work on the development of Shopify because I want to create an application that the user installs and places an external JavaScript file in their theme (preferably only load in products.liquid).

I experimented with some Rails code with ScriptTag, and I got a JavaScript file that needs to be inserted into HTML, but it never loads.

I made the following change to app / controllers / sessions_controller.rb after this code:

def show
  if response = request.env['omniauth.auth']
    sess = ShopifyAPI::Session.new(params[:shop], response['credentials']['token'])
    session[:shopify] = sess

(AFTER) MY CODE:

ShopifyAPI::Base.activate_session(sess)
ShopifyAPI::ScriptTag.create(:event => "onload", :src => "//x.com/x/myscript.js")

As I said, when I checked the item in Chrome, I see that myscript.js is inserted, but it never loads.

Is this somehow related to asynchronous, true? Is there a way to use ScriptTag and say that it is not asynchronous loading?

, ? API, , . , ?

Shopify Ruby on Rails, JavaScript ? , , ?

+3
1

, . . Shopify.com: > Asset

PUT

0

All Articles