0

I've built a mobile version of an existing website. The site I've built is completely static and relies only on HTML/CSS/JS. This site resides on the same server as the desktop version and is served from under http://example.com/mobile as a subdirectory. As such, I've set the <base> tag to:

<base href="http://example.com/mobile/"> 

The only access I get to the existing site is via FTP, so I don't have too many options to reconfigure the already existing server. And I don't want to either.

My mobile version is only somewhat functioning - all the <script> and <link> tags inside index.html correctly point to http://example.com/mobile/{js,css,img}, while links used inside js or css files look up to the top domain (e.g - http://example.com/img/image.png instead of http://example.com/mobile/img/image.png).

I can manually copy all the assets for the links to work, but since this is a Grunt project I figured there might be a smarter way to do this.

So, how can I have all internal asset links in js or scss files change when building (grunt build)? Something like:

site.css

// in dev body { background: url('/img/image.png') top left no-repeat; } // after building body { background: url('/mobile/img/image.png') top left no-repeat; } 

Thanks.

2
  • 1
    I would use a .htaccess and a rewrite rule for that. much simpler Commented Dec 10, 2014 at 12:05
  • Using .htaccess is an interesting idea, but turns out the server is IIS and I have no access to anything but the directory I'm deploying from. Thanks! Commented Dec 11, 2014 at 5:03

1 Answer 1

1

See grunt-replace or grunt-string-replace as tools that can help with this.

You could use either of these within your build task to process the changes you need.

The hardest part will be writing an accurate regex, but there are many regex testers/builders online that can help if you aren't expert at that.

Also, while .htaccess is a great idea for Apache based sites, it doesn't help if you are on Windows or on a cloud hosting solution that doesn't honor it.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.