Using CDN for css with rails

Options
Ephraim
Ephraim Member Posts: 2
edited November 2022 in Developer APIs

Looking for some guidance on how to upload precompiled CSS files, managing the file names and automate the uploading and accessing of those assets via CDN on rails

Tagged:

Comments

  • atdatu
    atdatu Member, Cloudinary Staff Posts: 9
    Options

    Hi,

    Thank you for reaching out! CSS should be uploaded as a "raw" asset type. To upload the file as a raw using ruby, please see the code snippet below:

    res = Cloudinary::Uploader.upload('vendor/cloudinary/cloudinary_php/samples/styles.css', :resource_
    type => 'raw')
    
    
    {"asset_id"=>"d3ceecf5cd4f3fc0a5041cddecf90fc1",                                                                    
     "public_id"=>"wsw6w6nmx8ro3jdkjics.css",                                                                           
      ...                                                           
     "resource_type"=>"raw",                 
      ...               
     "url"=>"http://res.cloudinary.com/<cloud_name>/raw/upload/v1669684687/wsw6w6nmx8ro3jdkjics.css",
     "secure_url"=>"https://res.cloudinary.com/<cloud_name>/raw/upload/v1669684687/wsw6w6nmx8ro3jdkjics.css",
     "folder"=>"",
    
    

    Then the CSS is accessible either the URL or Secure URL values. The first request may take longer as the CDN will need to reach Cloudinary, however, on subsequent requests, the CDN network should be able to serve the CSS file, see Cloudinary delivery lifecycle for more info on this. To rename the file, you may use Upload API's rename method.

    Let us know if you need further assistance.

    Regards,

    Anthony

    Developer Support Engineer

    Cloudinary