cssgoogle-apps-scriptweb-applications

Apps Script External Stylesheet


I am trying to use a single HTML stylesheet that I've created between multiple apps script web app projects. I have the HTML stylesheet hosted on an external site but cannot figure out the code to include that external stylesheet into my apps script projects.

I've currently got it working with the following code in my Index.html file:

<link rel="stylesheet" href="https://ssl.gstatic.com/docs/script/css/add-ons1.css">
<?!= include('stylesheet') ?>

The include function calls:

function include(filename) {
  return HtmlService.createHtmlOutputFromFile(filename)
  .getContent();
}

And my stylesheet is a separate HTML file in my Apps Script.

This all works well, but I'd like to have a central repository elsewhere (I've read that I cannot link to an Apps Script file in another project) for my stylesheet so that whatever changes I make will update to all of my Apps Script projects automatically.

To do this, I've uploaded my stylesheet.html to a website and have taken the link that points to the file (i.e. http://www.test.com/stylesheet.html) and tried to do the following without success:

<link rel="stylesheet" href="http://www.test.com/stylesheet.html">

I've placed this in the head element of my Index.html file, and I also tried it above the head element. Neither worked.

I've also tried to just use the include function that worked as mentioned above and modify my stylesheet.html to be blank except for:

<link rel="stylesheet" href="http://www.test.com/stylesheet.html">

None of this seems to work, wondering if anyone else has any thoughts on how this might be possible.


Solution

  • Host CSS file in Google Drive

    Create a .css stylesheet file and host it on Google Drive. Change the uploaded file permissions to publish it on the Web.

    Now copy the published file ID and use it to build the following URL:

    https://drive.google.com/uc?export=view&id=FILE-ID-GOES-HERE
    

    Now include the generated URL to your HTML page using the <link/> tag in this way:

    <link rel="stylesheet" href="google_drive_link_goes_here">
    

    Reference

    Host CSS or JS file on Google Drive