简体   繁体   中英

Dynamically creating javascript file in Rails 3.1

I am attempting to create a plug and play shopping cart in Rails 3.1 that allows users to add a shopping cart to their site by just adding a link to a javascript file. The items for sale are input on my end and stored in this js file and rendered with jquery templates. I currently have an action that renders the corresponding js, but I was wondering if there was a way to create a new minified js file for each site and link to this file in each site instead of the show action that renders the js.

For example, for store#1, I would like to create and save a js file called store1.js and serve that file instead of calling the show.js action that creates the javascipt array for the jquery templates every time.

You could try using action caching to have it only render the action once. Then you can utilize cache sweepers to invalidate the cached js when you make any updates that would change the information in the js.

I think that really might be your best option. Your going to go through a lot more trouble trying to get precompiled dynamic JS like that, especially if the content has a tendency to change at all.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM