Pre-procesador CSS en SQL
Crea una función de SQL Server para minimizar CSS. Puedes condensar el CSS en más de un 20%, o utiliza nuestra herramienta gratuita
Contexto
A menudo, el CSS se formatea de manera que sea fácil de leer para los humanos, pero esto implica tabulación, espaciado y nuevas líneas. Esta es una versión bastante simplificada de lo que construimos en el Optimizador de CSS (enlace más abajo), y se utiliza como parte de nuestro Sistema de Gestión de Contenidos.
El código recorre los distintos elementos que se insertan y los elimina, lo que da como resultado archivos CSS mucho más pequeños de lo habitual.
También realiza un reformateo básico de los colores y elimina los comentarios.
Puedes probar la herramienta en el siguiente enlace.
SQL
ALTER FUNCTION CSSProcessor(@CSS NVARCHAR(MAX)) RETURNS NVARCHAR(MAX) AS BEGINDECLARE @CSSReturn NVARCHAR(MAX)=@CSSWHILE CHARINDEX(' ',@CSSReturn,1)>0 SET @CSSReturn=REPLACE(@CSSReturn,' ',' ')WHILE CHARINDEX('; ',@CSSReturn,1)>0 SET @CSSReturn=REPLACE(@CSSReturn,'; ',';')WHILE CHARINDEX(' ;',@CSSReturn,1)>0 SET @CSSReturn=REPLACE(@CSSReturn,' ;',';')WHILE CHARINDEX(': ',@CSSReturn,1)>0 SET @CSSReturn=REPLACE(@CSSReturn,': ',':')WHILE CHARINDEX(' :',@CSSReturn,1)>0 SET @CSSReturn=REPLACE(@CSSReturn,' :',':')WHILE CHARINDEX(', ',@CSSReturn,1)>0 SET @CSSReturn=REPLACE(@CSSReturn,', ',',')WHILE CHARINDEX(' ,',@CSSReturn,1)>0 SET @CSSReturn=REPLACE(@CSSReturn,' ,',',')WHILE CHARINDEX('} ',@CSSReturn,1)>0 SET @CSSReturn=REPLACE(@CSSReturn,'} ','}')WHILE CHARINDEX(' }',@CSSReturn,1)>0 SET @CSSReturn=REPLACE(@CSSReturn,' }','}')WHILE CHARINDEX(' {',@CSSReturn,1)>0 SET @CSSReturn=REPLACE(@CSSReturn,' {','{')WHILE CHARINDEX('{ ',@CSSReturn,1)>0 SET @CSSReturn=REPLACE(@CSSReturn,'{ ','{')WHILE CHARINDEX(';}',@CSSReturn,1)>0 SET @CSSReturn=REPLACE(@CSSReturn,';}','}')WHILE CHARINDEX('ffffff',@CSSReturn,1)>0 SET @CSSReturn=REPLACE(@CSSReturn,'ffffff','fff')WHILE CHARINDEX('eeeeee',@CSSReturn,1)>0 SET @CSSReturn=REPLACE(@CSSReturn,'eeeeee','eee')WHILE CHARINDEX('dddddd',@CSSReturn,1)>0 SET @CSSReturn=REPLACE(@CSSReturn,'dddddd','ddd')WHILE CHARINDEX('cccccc',@CSSReturn,1)>0 SET @CSSReturn=REPLACE(@CSSReturn,'cccccc','ccc')WHILE CHARINDEX('bbbbbb',@CSSReturn,1)>0 SET @CSSReturn=REPLACE(@CSSReturn,'bbbbbb','bbb')WHILE CHARINDEX('aaaaaa',@CSSReturn,1)>0 SET @CSSReturn=REPLACE(@CSSReturn,'aaaaaa','aaa')WHILE CHARINDEX('999999',@CSSReturn,1)>0 SET @CSSReturn=REPLACE(@CSSReturn,'999999','999')WHILE CHARINDEX('888888',@CSSReturn,1)>0 SET @CSSReturn=REPLACE(@CSSReturn,'888888','888')WHILE CHARINDEX('777777',@CSSReturn,1)>0 SET @CSSReturn=REPLACE(@CSSReturn,'777777','777')WHILE CHARINDEX('666666',@CSSReturn,1)>0 SET @CSSReturn=REPLACE(@CSSReturn,'666666','666')WHILE CHARINDEX('555555',@CSSReturn,1)>0 SET @CSSReturn=REPLACE(@CSSReturn,'555555','555')WHILE CHARINDEX('444444',@CSSReturn,1)>0 SET @CSSReturn=REPLACE(@CSSReturn,'444444','444')WHILE CHARINDEX('333333',@CSSReturn,1)>0 SET @CSSReturn=REPLACE(@CSSReturn,'333333','333')WHILE CHARINDEX('222222',@CSSReturn,1)>0 SET @CSSReturn=REPLACE(@CSSReturn,'222222','222')WHILE CHARINDEX('111111',@CSSReturn,1)>0 SET @CSSReturn=REPLACE(@CSSReturn,'111111','111')WHILE CHARINDEX('000000',@CSSReturn,1)>0 SET @CSSReturn=REPLACE(@CSSReturn,'000000','000')WHILE CHARINDEX('auto auto auto auto',@CSSReturn,1)>0 SET @CSSReturn=REPLACE(@CSSReturn,'auto auto auto auto','auto')WHILE CHARINDEX(CHAR(13)+CHAR(10),@CSSReturn,1)>0 SET @CSSReturn=REPLACE(@CSSReturn,CHAR(13)+CHAR(10),'')WHILE CHARINDEX(CHAR(10),@CSSReturn,1)>0 SET @CSSReturn=REPLACE(@CSSReturn,CHAR(10),'')WHILE CHARINDEX(CHAR(13),@CSSReturn,1)>0 SET @CSSReturn=REPLACE(@CSSReturn,CHAR(13),'')WHILE CHARINDEX(CHAR(9),@CSSReturn,1)>0 SET @CSSReturn=REPLACE(@CSSReturn,CHAR(9),'')DECLARE @St INT,@En INTWHILE CHARINDEX('/*',@CSSReturn,1)>0 AND CHARINDEX('*/',@CSSReturn,CHARINDEX('*/',@CSSReturn,CHARINDEX('/*',@CSSReturn,1)))>0 BEGINSET @St=CHARINDEX('/*',@CSSReturn,1)SET @En=CHARINDEX('*/',@CSSReturn,@St)SET @CSSReturn=STUFF(@CSSReturn,@St,@En-@St+2,'')ENDRETURN @CSSReturnENDGO