Forum Discussion

hiraldesai's avatar
10 years ago

Endpoint to render custom assets

Hi,

 

I have a question about using endpoints to render assets (mainly images).

 

We have a local dev setup to use Grunt to compile our custom JS & CSS, mainly because it allows us to write modular JavaScript code and compile/bundle it in one file to be uploaded to studio. This approach works fine with JavaScript no problems. For CSS generation however, we use modular less files to avoid having to write too much vanilla CSS. The only problem with this is when the CSS needs to reference background images that are also custom assets within our community. 

 

We initially tried something like this in our less files:

 

// Get less to ignore url when compiling
background: ~'url(${asset.get("/html/assets/asset_name.gif")})'

This works with following limitations:

  1. Hard to do local testing
  2. You can only copy paste the CSS inside "Skin CSS" field of the community admin

 

I thought I would create a custom endpoint that would take path of the asset as url parameter and render the asset using asset & http.client  freemarker objects. If I can get this endpoint to render the image content, I can then just reference the URL to this endpoint inside the less file and upload & include the generated CSS file in the head tag for all pages saving some effort in the process. Just wondering if it's possible to do since I can't seem to set a content type of image/gif or image/jpeg inside an endpoint.

 

 

Any help/suggestions/work-arounds will be much appreciated.

 

Kind Regards,

Hiral

  • DougS's avatar
    DougS
    Khoros Oracle

    Hi Hiral,

     

    Do you use a CDN (or are you considering adding one)?  If so, using an endpoint will probably not be a good approach, as it will require a call to the Lithium server to get an asset instead of going over the CDN.  Also, I don't think we allow you to stream out assets via an endpoint.  

     

    You could try using an endpoint to render your less files (that might also take more time that you'd like), or you could use the static asset host name in the URLs in your less files instead of using asset.get.  Adding eddielo to this thread in case he has a suggestion that I might have missed.

     

    -Doug