duanjiaren8188 2014-05-04 06:37
浏览 66

html缩小后,Swipe.js停止工作

Due to big time lags because of a remote database, I am working on on a PHP/cron script fetching webpages from the CMS and saving them as static webpages. Then serving the static webpages to visitors. I have also decided to try and minify the resultant html file before saving it. All the above works pretty well (fetch, remove comments, minify, save), BUT swipe.js stops working.

My basic code is:

  // get the webpage from CMS
$contents = file_get_contents($cms_url);

  // remove comments
$contents = preg_replace('/<!--(?!\s*(?:\[if [^\]]+]|<!|>))(?:(?!-->).)*-->/Uis', '', $contents);

  // minify
$contents = preg_replace('/^\s+|
||\s+$/m', '', $contents);  

  // delete old cached copy
unlink($web_url);

  // save new copy
file_put_contents($web_url , $contents);

After a lot of experimenting, I have come to the conclusion that swipe.js issue begins after removing the newline character ( ).

Has anyone dealt with this issue before? Is it a jQuery issue with the way they look for children as that seems to be the way swipe determines the correct divs? Or is it a swipe.js issue? Or is it the way I am removing the newline character? Or??

additional notes ----

Did some more experimenting with the minifaction aspect by using third party html minification tools and the same issue occurs with those minified files. So my PHP code is not the contributing factor.

It seems to be an issue with either jQuery or Swipe.js, as once the new line characters are removed the targeted content wrapper div isn't being modified.

Swipe.js is in an external file so is not be modified by my minifaction on the html files.

None of the other jQuery functions on the page are being effected by the minification.

  • 写回答

1条回答 默认 最新

  • duanoucuo7045 2014-05-05 04:04
    关注

    Got it solved. It was a result of the minified file essentially being one line and the double slashes // of a javascript comment were turning all JS after it into a continuation of that comment, hence non-functional.

    I removed the javascript comment from the template and everything works beautifully.

    I had planned to add JS comments to my regex, but as there is only one JS comment within all the templates it was easier to delete to comment, than add the extra processing to the code.

    评论

报告相同问题?

悬赏问题

  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等
  • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
  • ¥15 qt6.6.3 基于百度云的语音识别 不会改
  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来