Insert page specific CSS or JS using content_for

There might be cases where you want to insert some CSS or JS snippet into a specific page only , for example inserting Stripe JS and CSS only on the payment page, but not on other pages of the same controller.If you insert the snippet into layout/application.html.erb , it will be available to all the pages, which might slow down the load time of other pages which doesn’t use the script!.
Insert page specific CSS or JS using content_for #ruby #rubydeveloper #rubyonrails #css https://www.rubyonrails.ba/single/insert-page-specific-css-or-js-using-content_for

Nezir Zahirovic

Contractor Ruby On Rails (8+ years) / MCPD .Net / C# / Asp.Net / CSS / SQL / (11 years)

related articles