User generated custom css

前端 未结 4 2001
忘掉有多难
忘掉有多难 2021-01-06 21:36

Hey, anyone have any idea what the best way to allow users to save custom css would be? Specifically, there are about 4 color values that I would like to allow a user to ch

4条回答
  •  执念已碎
    2021-01-06 22:24

    Creating a custom css file adds another request the browser has to make so you would need to make sure your setting up the headers correctly to cache it. If the user does change their settings you would need do something to ensure the browser immediately stops cashing the old css file and loads the new file. One way to do this is to change the url of the css file.

    Example:

    /usercustom.css?version=(last saved date hash)

    Instead I would use your first approach and create a JSON array that you inject into the page and then you use your javascript framework to load and use the array to style the page.

    You could also store the color values in the cookie from the server and use and or write to them on the client.

提交回复
热议问题